No Field Error Updating Values in Firestore












0















I am attempting to update a document in firestore using the golang library. For some reason I am getting an error: "no field "BirthYear" error and I am not sure why. Birth year is definitely one of the values that I am attempting to update.



I assume that I have configured my struct incorrectly but I cannot see how. Here is my struct and my update code:



sharedstructs.Profile



type Profile struct {
UID string `json:"UID" firestore:"UID"`
ContactEmail string `json:"ContactEmail,omitempty" firestore:"ContactEmail"`
BirthMonth int64 `json:"BirthMonth,omitempty" firestore:"BirthMonth"`
BirthYear int64 `json:"BirthYear,omitempty" firestore:"BirthYear"`
Gender string `json:"Gender,omitempty" firestore:"Gender"`
Unit string `json:"Unit,omitempty" firestore:"Unit"`
CurrentStatus string `json:"CurrentStatus,omitempty" firestore:"CurrentStatus"`
Country string `json:"Country,omitempty" firestore:"Country"`
ExperienceType string `json:"ExperienceType,omitempty" firestore:"ExperienceType"`
DateJoined time.Time `json:"DateJoined,omitempty" firestore:"DateJoined"`
Abilities Ability `json:"Abilities,omitempty" firestore:"Abilities"`
Goals Goal `json:"Goals,omitempty" firestore:"Goals"`
Roles Role `json:"Roles,omitempty" firestore:"Roles"`
TermsAndConditions TermsAndConditions `json:"TermsAndConditions,omitempty" firestore:"TermsAndConditions"`
TimeZone string `json:"TimeZone,omitempty" firestore:"TimeZone"`
BaselineTests BaselineTestResults `json:"BaselineTests,omitempty" firestore:"BaselineTests"`
UpdatedDate time.Time `json:"UpdatedDate,omitempty" firestore:"UpdatedDate"`
FirstName *string `json:"FirstName,omitempty" firestore:"FirstName"`
LastName string `json:"LastName,omitempty" firestore:"LastName"`
DisplayName string `json:"DisplayName,omitempty" firestore:"DisplayName"`
}


Update Function



func updateProfileWithSpecficValues(documentName string, values sharedstructs.Profile, overwriteValues string) error {
ctx := context.Background()
app := firestorehelper.GetFirestoreApp()

client, err := app.Firestore(ctx)
if err != nil {
return err
}
defer client.Close()

//Set the updated date
values.UpdatedDate = time.Now()
wr, error := client.Doc(collectionName+"/"+documentName).Set(ctx, values, firestore.Merge(overwriteValues))
if error != nil {
return error
}
fmt.Println(wr.UpdateTime)
//Assume success
return nil
}









share|improve this question























  • Your code looks correct, you should log.Printf("%v - %v", values, overwriteValues) and check the result

    – thst
    Jan 2 at 21:32
















0















I am attempting to update a document in firestore using the golang library. For some reason I am getting an error: "no field "BirthYear" error and I am not sure why. Birth year is definitely one of the values that I am attempting to update.



I assume that I have configured my struct incorrectly but I cannot see how. Here is my struct and my update code:



sharedstructs.Profile



type Profile struct {
UID string `json:"UID" firestore:"UID"`
ContactEmail string `json:"ContactEmail,omitempty" firestore:"ContactEmail"`
BirthMonth int64 `json:"BirthMonth,omitempty" firestore:"BirthMonth"`
BirthYear int64 `json:"BirthYear,omitempty" firestore:"BirthYear"`
Gender string `json:"Gender,omitempty" firestore:"Gender"`
Unit string `json:"Unit,omitempty" firestore:"Unit"`
CurrentStatus string `json:"CurrentStatus,omitempty" firestore:"CurrentStatus"`
Country string `json:"Country,omitempty" firestore:"Country"`
ExperienceType string `json:"ExperienceType,omitempty" firestore:"ExperienceType"`
DateJoined time.Time `json:"DateJoined,omitempty" firestore:"DateJoined"`
Abilities Ability `json:"Abilities,omitempty" firestore:"Abilities"`
Goals Goal `json:"Goals,omitempty" firestore:"Goals"`
Roles Role `json:"Roles,omitempty" firestore:"Roles"`
TermsAndConditions TermsAndConditions `json:"TermsAndConditions,omitempty" firestore:"TermsAndConditions"`
TimeZone string `json:"TimeZone,omitempty" firestore:"TimeZone"`
BaselineTests BaselineTestResults `json:"BaselineTests,omitempty" firestore:"BaselineTests"`
UpdatedDate time.Time `json:"UpdatedDate,omitempty" firestore:"UpdatedDate"`
FirstName *string `json:"FirstName,omitempty" firestore:"FirstName"`
LastName string `json:"LastName,omitempty" firestore:"LastName"`
DisplayName string `json:"DisplayName,omitempty" firestore:"DisplayName"`
}


Update Function



func updateProfileWithSpecficValues(documentName string, values sharedstructs.Profile, overwriteValues string) error {
ctx := context.Background()
app := firestorehelper.GetFirestoreApp()

client, err := app.Firestore(ctx)
if err != nil {
return err
}
defer client.Close()

//Set the updated date
values.UpdatedDate = time.Now()
wr, error := client.Doc(collectionName+"/"+documentName).Set(ctx, values, firestore.Merge(overwriteValues))
if error != nil {
return error
}
fmt.Println(wr.UpdateTime)
//Assume success
return nil
}









share|improve this question























  • Your code looks correct, you should log.Printf("%v - %v", values, overwriteValues) and check the result

    – thst
    Jan 2 at 21:32














0












0








0








I am attempting to update a document in firestore using the golang library. For some reason I am getting an error: "no field "BirthYear" error and I am not sure why. Birth year is definitely one of the values that I am attempting to update.



I assume that I have configured my struct incorrectly but I cannot see how. Here is my struct and my update code:



sharedstructs.Profile



type Profile struct {
UID string `json:"UID" firestore:"UID"`
ContactEmail string `json:"ContactEmail,omitempty" firestore:"ContactEmail"`
BirthMonth int64 `json:"BirthMonth,omitempty" firestore:"BirthMonth"`
BirthYear int64 `json:"BirthYear,omitempty" firestore:"BirthYear"`
Gender string `json:"Gender,omitempty" firestore:"Gender"`
Unit string `json:"Unit,omitempty" firestore:"Unit"`
CurrentStatus string `json:"CurrentStatus,omitempty" firestore:"CurrentStatus"`
Country string `json:"Country,omitempty" firestore:"Country"`
ExperienceType string `json:"ExperienceType,omitempty" firestore:"ExperienceType"`
DateJoined time.Time `json:"DateJoined,omitempty" firestore:"DateJoined"`
Abilities Ability `json:"Abilities,omitempty" firestore:"Abilities"`
Goals Goal `json:"Goals,omitempty" firestore:"Goals"`
Roles Role `json:"Roles,omitempty" firestore:"Roles"`
TermsAndConditions TermsAndConditions `json:"TermsAndConditions,omitempty" firestore:"TermsAndConditions"`
TimeZone string `json:"TimeZone,omitempty" firestore:"TimeZone"`
BaselineTests BaselineTestResults `json:"BaselineTests,omitempty" firestore:"BaselineTests"`
UpdatedDate time.Time `json:"UpdatedDate,omitempty" firestore:"UpdatedDate"`
FirstName *string `json:"FirstName,omitempty" firestore:"FirstName"`
LastName string `json:"LastName,omitempty" firestore:"LastName"`
DisplayName string `json:"DisplayName,omitempty" firestore:"DisplayName"`
}


Update Function



func updateProfileWithSpecficValues(documentName string, values sharedstructs.Profile, overwriteValues string) error {
ctx := context.Background()
app := firestorehelper.GetFirestoreApp()

client, err := app.Firestore(ctx)
if err != nil {
return err
}
defer client.Close()

//Set the updated date
values.UpdatedDate = time.Now()
wr, error := client.Doc(collectionName+"/"+documentName).Set(ctx, values, firestore.Merge(overwriteValues))
if error != nil {
return error
}
fmt.Println(wr.UpdateTime)
//Assume success
return nil
}









share|improve this question














I am attempting to update a document in firestore using the golang library. For some reason I am getting an error: "no field "BirthYear" error and I am not sure why. Birth year is definitely one of the values that I am attempting to update.



I assume that I have configured my struct incorrectly but I cannot see how. Here is my struct and my update code:



sharedstructs.Profile



type Profile struct {
UID string `json:"UID" firestore:"UID"`
ContactEmail string `json:"ContactEmail,omitempty" firestore:"ContactEmail"`
BirthMonth int64 `json:"BirthMonth,omitempty" firestore:"BirthMonth"`
BirthYear int64 `json:"BirthYear,omitempty" firestore:"BirthYear"`
Gender string `json:"Gender,omitempty" firestore:"Gender"`
Unit string `json:"Unit,omitempty" firestore:"Unit"`
CurrentStatus string `json:"CurrentStatus,omitempty" firestore:"CurrentStatus"`
Country string `json:"Country,omitempty" firestore:"Country"`
ExperienceType string `json:"ExperienceType,omitempty" firestore:"ExperienceType"`
DateJoined time.Time `json:"DateJoined,omitempty" firestore:"DateJoined"`
Abilities Ability `json:"Abilities,omitempty" firestore:"Abilities"`
Goals Goal `json:"Goals,omitempty" firestore:"Goals"`
Roles Role `json:"Roles,omitempty" firestore:"Roles"`
TermsAndConditions TermsAndConditions `json:"TermsAndConditions,omitempty" firestore:"TermsAndConditions"`
TimeZone string `json:"TimeZone,omitempty" firestore:"TimeZone"`
BaselineTests BaselineTestResults `json:"BaselineTests,omitempty" firestore:"BaselineTests"`
UpdatedDate time.Time `json:"UpdatedDate,omitempty" firestore:"UpdatedDate"`
FirstName *string `json:"FirstName,omitempty" firestore:"FirstName"`
LastName string `json:"LastName,omitempty" firestore:"LastName"`
DisplayName string `json:"DisplayName,omitempty" firestore:"DisplayName"`
}


Update Function



func updateProfileWithSpecficValues(documentName string, values sharedstructs.Profile, overwriteValues string) error {
ctx := context.Background()
app := firestorehelper.GetFirestoreApp()

client, err := app.Firestore(ctx)
if err != nil {
return err
}
defer client.Close()

//Set the updated date
values.UpdatedDate = time.Now()
wr, error := client.Doc(collectionName+"/"+documentName).Set(ctx, values, firestore.Merge(overwriteValues))
if error != nil {
return error
}
fmt.Println(wr.UpdateTime)
//Assume success
return nil
}






database firebase go google-cloud-firestore






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 20:59









mornindewmornindew

5783721




5783721













  • Your code looks correct, you should log.Printf("%v - %v", values, overwriteValues) and check the result

    – thst
    Jan 2 at 21:32



















  • Your code looks correct, you should log.Printf("%v - %v", values, overwriteValues) and check the result

    – thst
    Jan 2 at 21:32

















Your code looks correct, you should log.Printf("%v - %v", values, overwriteValues) and check the result

– thst
Jan 2 at 21:32





Your code looks correct, you should log.Printf("%v - %v", values, overwriteValues) and check the result

– thst
Jan 2 at 21:32












1 Answer
1






active

oldest

votes


















0














https://godoc.org/cloud.google.com/go/firestore#Merge




Merge returns a SetOption that causes only the given field paths to be
overwritten. Other fields on the existing document will be untouched.
It is an error if a provided field path does not refer to a value in the data passed to Set.




You are sending no BirthYear (default value) in values, but BirthYear is specified in overwriteValues.






share|improve this answer
























  • Hmm, that would have made sense. I set a breakpoint and doublechecked both my values and my overwriteValues had "BirthYear" in it. Not sure why it is throwing that error

    – mornindew
    Jan 2 at 22:34











  • Do you have not default value of BirthYear in every item in values? Missing that will cause an error.

    – Dmitry Harnitski
    Jan 2 at 22:47












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013105%2fno-field-error-updating-values-in-firestore%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














https://godoc.org/cloud.google.com/go/firestore#Merge




Merge returns a SetOption that causes only the given field paths to be
overwritten. Other fields on the existing document will be untouched.
It is an error if a provided field path does not refer to a value in the data passed to Set.




You are sending no BirthYear (default value) in values, but BirthYear is specified in overwriteValues.






share|improve this answer
























  • Hmm, that would have made sense. I set a breakpoint and doublechecked both my values and my overwriteValues had "BirthYear" in it. Not sure why it is throwing that error

    – mornindew
    Jan 2 at 22:34











  • Do you have not default value of BirthYear in every item in values? Missing that will cause an error.

    – Dmitry Harnitski
    Jan 2 at 22:47
















0














https://godoc.org/cloud.google.com/go/firestore#Merge




Merge returns a SetOption that causes only the given field paths to be
overwritten. Other fields on the existing document will be untouched.
It is an error if a provided field path does not refer to a value in the data passed to Set.




You are sending no BirthYear (default value) in values, but BirthYear is specified in overwriteValues.






share|improve this answer
























  • Hmm, that would have made sense. I set a breakpoint and doublechecked both my values and my overwriteValues had "BirthYear" in it. Not sure why it is throwing that error

    – mornindew
    Jan 2 at 22:34











  • Do you have not default value of BirthYear in every item in values? Missing that will cause an error.

    – Dmitry Harnitski
    Jan 2 at 22:47














0












0








0







https://godoc.org/cloud.google.com/go/firestore#Merge




Merge returns a SetOption that causes only the given field paths to be
overwritten. Other fields on the existing document will be untouched.
It is an error if a provided field path does not refer to a value in the data passed to Set.




You are sending no BirthYear (default value) in values, but BirthYear is specified in overwriteValues.






share|improve this answer













https://godoc.org/cloud.google.com/go/firestore#Merge




Merge returns a SetOption that causes only the given field paths to be
overwritten. Other fields on the existing document will be untouched.
It is an error if a provided field path does not refer to a value in the data passed to Set.




You are sending no BirthYear (default value) in values, but BirthYear is specified in overwriteValues.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 21:39









Dmitry HarnitskiDmitry Harnitski

3,86311834




3,86311834













  • Hmm, that would have made sense. I set a breakpoint and doublechecked both my values and my overwriteValues had "BirthYear" in it. Not sure why it is throwing that error

    – mornindew
    Jan 2 at 22:34











  • Do you have not default value of BirthYear in every item in values? Missing that will cause an error.

    – Dmitry Harnitski
    Jan 2 at 22:47



















  • Hmm, that would have made sense. I set a breakpoint and doublechecked both my values and my overwriteValues had "BirthYear" in it. Not sure why it is throwing that error

    – mornindew
    Jan 2 at 22:34











  • Do you have not default value of BirthYear in every item in values? Missing that will cause an error.

    – Dmitry Harnitski
    Jan 2 at 22:47

















Hmm, that would have made sense. I set a breakpoint and doublechecked both my values and my overwriteValues had "BirthYear" in it. Not sure why it is throwing that error

– mornindew
Jan 2 at 22:34





Hmm, that would have made sense. I set a breakpoint and doublechecked both my values and my overwriteValues had "BirthYear" in it. Not sure why it is throwing that error

– mornindew
Jan 2 at 22:34













Do you have not default value of BirthYear in every item in values? Missing that will cause an error.

– Dmitry Harnitski
Jan 2 at 22:47





Do you have not default value of BirthYear in every item in values? Missing that will cause an error.

– Dmitry Harnitski
Jan 2 at 22:47




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013105%2fno-field-error-updating-values-in-firestore%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]