How to update schema if you are using NodeJS

81 views
Skip to first unread message

Varun Shivaprasad

unread,
Mar 16, 2016, 9:15:04 AM3/16/16
to Google App Engine
I created a new instance and deployed a nodejs based application. I am using google datastore as database. Now i want to edit some fields in Kind. Change properties of the fields that are already there and add some new properties. If i do add new properties, they are not getting reflected in the schema that is already there. How do I update schema now? Should i use python now just to update schema or is there anyway i can do it from my nodejs config.

Nicholas (Google Cloud Support)

unread,
Mar 18, 2016, 2:15:26 PM3/18/16
to Google App Engine
Thank you for posting your questions here.

Though the examples here are for Python, the behavior is the same for Javascript in Nodejs. Datastore is designed such that all entities need not have the same properties. Saving a given entity with new properties will add those properties and values to said entity. Other entities of the same kind may not have those same new properties. As documented in the aforementioned article, entities written to the Datastore after adding said properties will now have those properties. In addition, whenever an entity of that Kind is read, the entity will be populated with values for those new properties either using the data stored or default values you've specified. With this in mind, Datastore does not require that all entities have the same properties.

If you must query entities using these new properties however, you will need to update your existing entities. To do so, you'll essentially need to load all entities and save them again after setting values to said properties. This can be done using the Datastore APIs provided for Node and therefore do not require the use of Python.

In short, schemas do not automatically apply to all entities of a articular kind. That must be done manually by updating the entities with values for new or updated properties.

I hope this answers your questions.
Reply all
Reply to author
Forward
0 new messages