Skip to content

Setting Property value types for Datastore Entities #553

Description

@byrneciaran

How do I set Property value types (e.g. dateTimeValue, IntegerValue, etc.) when inserting my entities in the example below. At the moment the Property value types are all set as strings

var entry = {
    "title":"Title",
    "start":"2014-02-01T09:28:56.321-10:00"
};

var ds = gcloud.datastore.dataset();
var key = ds.key(['Entry', 'Foo', 'Todo']);

ds.save({
    key: key,
    data: entry
}, callback);

Activity

  1. added
    type: questionRequest for information or clarification. Not an issue.
    api: datastoreIssues related to the Datastore API.
    on May 8, 2015
  2. jgeewax commented on May 8, 2015

    @jgeewax
    Contributor

    I believe you can do this by passing in the actual Date type object. Looks like the conversion to the proper type in the request is done here: https://github.com/GoogleCloudPlatform/gcloud-node/blob/bc2b57ce4e2d84a8d2ff722d677ddfe681fc8d00/lib/datastore/entity.js#L380

    I also think that if you want to distinguish between Int and Double, you can use the gcloud.datastore.double and gcloud.datastore.int` methods (see http://googlecloudplatform.github.io/gcloud-node/#/docs/master/datastore)

    Ie, this should work

    var entry = {
        "title": "Title",
        "start": new Date(),
        "myDouble": gcloud.datastore.double(3.0)
    };
    
    var ds = gcloud.datastore.dataset();
    var key = ds.key(['Entry', 'Foo', 'Todo']);
    
    ds.save({
        key: key,
        data: entry
    }, callback);
  3. ryanseys commented on May 8, 2015

    @ryanseys
    Contributor

    Perhaps we should add a few more examples to the dataset#save docs to address these different cases.

  4. byrneciaran commented on May 8, 2015

    @byrneciaran
    Author

    Ah ok, I admit I'm struggling to make sense of the documentation. I think the reason for this is that reading the general Datastore documentation for the first time (https://cloud.google.com/datastore/docs/concepts/entities#Datastore_Properties_and_value_types) makes reference to doing something like:

    var entity = {
      key: { path: [{ kind: 'Employee' }] },
      properties: {
        firstName: { stringValue: 'Antonio' },
        lastName: { stringValue: 'Salieri' },
        hireDate: { dateTimeValue: '2013-05-14T13:01:00.234Z' },
        attendedHrTraining: { booleanValue: true }
      }
    };
    datastore.commit({
      mutation: { insertAutoId: [entity] },
      mode: 'NON_TRANSACTIONAL'
    }).execute(callback);

    which uses the googleapis module. Maybe it will help to clarify in the documentation the difference between using the googleapis module vs the gcloud module in Node as I'm finding I'm stumbling across both while searching for Datastore information on Node.

  5. jgeewax commented on May 8, 2015

    @jgeewax
    Contributor

    That's a great point @byrneciaran. I'm going to open another issue for us to put a banner saying that we're not the same as the googleapis module... Not sure how else we can clarify this without changing documentation on cloud.google.com (which we shouldn't really do until we hit v1.0). If you have any suggestions, definitely let us know!

    I'm going to close out this issue as I think we've answered the question, but feel free to re-open if you think that's a mistake, and follow #554 if you're interested in providing any feedback on the updates we're making to the documentation.

  6. 21 remaining items

  7. added a commit that references this issue on Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the Datastore API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions