Skip to content

Commit e4d85b8

Browse files
Merge pull request #398 from ryanseys/rs--datastore-save-readme
Add dataset.save example to README
2 parents b32e77f + 89ac244 commit e4d85b8

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,31 @@ dataset = gcloud.datastore.dataset({
148148
dataset.get(dataset.key(['Product', 'Computer']), function(err, entity) {
149149
console.log(err || entity);
150150
});
151+
152+
// Save data to datastore
153+
var blogPostData = {
154+
title: 'How to make the perfect homemade pasta',
155+
tags: ['pasta', 'homemade'],
156+
author: 'Silvano',
157+
isDraft: true,
158+
wordCount: 450,
159+
};
160+
161+
var theKey = ds.key('BlogPost');
162+
163+
dataset.save({
164+
key: theKey,
165+
data: blogPostData
166+
}, function(err) {
167+
// theKey has been updated with an id so you can
168+
// do more operations with it. Such as an update:
169+
dataset.save({
170+
key: theKey,
171+
data: { isDraft: false }
172+
}, function(err) {
173+
// The blog post is now published!
174+
});
175+
});
151176
```
152177

153178
## Google Cloud Storage

0 commit comments

Comments
 (0)