You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possibly incorrect example on the datastore preview in README.md #812
The following example seems incorrect, as datastore doesn't support partial update:
dataset.save({
key: blogPostKey,
data: blogPostData
}, function(err) {
// `blogPostKey` has been updated with an ID so you can do more operations
// with it, such as an update:
dataset.save({
key: blogPostKey,
data: {
isDraft: false
}
}, function(err) {
if (!err) {
// The blog post is now published!
}
});
});
It looks like the second update will overwrite the blog post with a single property entity {isDraft: false}
An upsert mutation is not a partial update (an upsert is akin to a force write, it will insert the entity or update it if an entity already exists for the provided key).
The example I quoted above is indeed incorrect, the resulting BlogPost entity contains only {isDraft: false}.
Here is an updated getting started example that doesn't have this issue:
dataset.save({
key: blogPostKey,
data: blogPostData
}, function(err) {
// `blogPostKey` has been updated with an ID so you can do more operations
// with it, such as an update:
blogPostData.isDraft = false;
dataset.save({
key: blogPostKey,
data: blogPostData
}, function(err) {
if (!err) {
// The blog post is now published!
}
});
});
Good to know! Thanks for not letting me go on misunderstanding an upsert. Would you be able to send your example in a PR? Either way, thanks for catching this.
Activity
stephenplusplus commentedon Aug 19, 2015
Datastore does support partial updates in the form of an "upsert mutation" -- https://cloud.google.com/datastore/docs/concepts/entities (best link I could find to explain it). Our
savemethod tries to pick the best one that applies: http://googlecloudplatform.github.io/gcloud-node/#/docs/v0.19.0/datastore/transaction?method=saveclement commentedon Aug 19, 2015
An upsert mutation is not a partial update (an upsert is akin to a force write, it will insert the entity or update it if an entity already exists for the provided key).
The example I quoted above is indeed incorrect, the resulting BlogPost entity contains only
{isDraft: false}.Here is a (failing) test to illustrate further:
Here is an updated getting started example that doesn't have this issue:
stephenplusplus commentedon Aug 19, 2015
Good to know! Thanks for not letting me go on misunderstanding an upsert. Would you be able to send your example in a PR? Either way, thanks for catching this.
roboshoes commentedon Jan 7, 2016
Appreciate this discussion @clement. I've been wondering why it kept overwriting my entire document, when I wanted to simply update one field.
fix(deps): require google-gax v2.12.0 (#812)
fix: add an internal getOperation method in operation client (#812)
chore(deps): update codecov/codecov-action action to v3 (#812)
chore(deps): update codecov/codecov-action action to v3 (#812)
1 remaining item
chore(deps): update codecov/codecov-action action to v3 (#812)
chore(deps): update codecov/codecov-action action to v3 (#812)
chore(deps): update codecov/codecov-action action to v3 (#812)
chore(deps): update codecov/codecov-action action to v3 (#812)
chore(deps): update codecov/codecov-action action to v3 (#812)
chore(deps): update dependency @types/mocha to v8 (#812)
test: add test for x-goog-api-client header (#812)
fix: retry Session not found for Database.run(..) (#812)
fix(deps): update dependency @google-cloud/storage to v5 (#812)
build: add gtoken error with code (#812)
test: add test for x-goog-api-client header (googleapis#812)
chore: clean up Node.js TOC for cloud-rad (#812)
chore: clean up Node.js TOC for cloud-rad (#812)
chore: clean up Node.js TOC for cloud-rad (#812)
chore: clean up Node.js TOC for cloud-rad (googleapis#812)