Repository navigation
@google-cloud/datastore v7 no longer works, ex key operations #2046
Description
Activity
- addedapi: datastoreIssues related to the Datastore API.Issues related to the Datastore API.
on Mar 3, 2017 Sorry for the trouble you're having. To be clear, you're saying the method
datastore.keydoes not exist? I checked this with@google-cloud/datastorev0.7.0:var datastore = require('@google-cloud/datastore')({ auth info }) var key = datastore.key(['Product', 'Computer'])
This does not throw, the method does indeed exist. Is it possible something went wrong during your upgrade process? Make sure to
rm -rf node_modulesandnpm cache cleanbefore upgrading.They are billing me for google data store use.
We are a layer in front of the Google Cloud APIs that we support. Therefore, your use of our API goes directly through to the actual APIs, and costs will be incurred. It is possible to use the Datastore emulator to avoid costs: https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.47.0/datastore -- search for "The Datastore emulator" to find the relevant section.
Re-reading your last question, perhaps you meant your employer is considering using this library, and you want to know how stable this project is. I would refer you to our "Versioning" section, which communicates how we define the stability of our APIs-- scroll up the README to see each API's status. @google-cloud/datastore is in Beta status, and we intend to go stable within the coming months.
things you should be regression testing
We have such tests here: https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/packages/datastore/system-test/datastore.js.
It's certainly possible for mistakes to happen and bugs to exist, so if you are still experiencing the error, please let me know, with more precise detail, how I can reproduce.
After insert, you can't get a key, you must run a query now. This worked in v6. In v7 I have to issue a query:
const key_ = DS.key( TCONTENT ) const row = { key: key_, data: jDObj } const pro = new Promise(function(resolve, reject){ DS.insert(row).then(function(ret){
... just to get the new PK of the inserted object.
Also in v6 I could query and return just the key. No longer works. In v7 I have to:
,existsContentKey: function(sdom, section, urn) { const query = DS.createQuery([TCONTENT]) .filter( 'sdom', '=', sdom ) .filter( 'section', '=', section ) .filter( 'urn', '=', urn ) const pro = new Promise(function(resolve, reject){ DS.runQuery(query).then(function(res){ const rows = res[0] if(rows.length == 0) { // reject() } else if (rows.length == 1) { const row = rows[0] const key = row[DS.KEY] //console.log(key.id) resolve(key) } else { // WTF? reject('major error!!!') }//else })//DSq })//pro return pro }//exists
Here's how to get the key of an object that you insert:
var key = datastore.key('Kind') var row = { key: key, data: { test: true } } datastore.insert(row).then(function(resp) { // ID is automatically assigned: console.log(key.id) // Or, get it from the raw API response: var apiResponse = resp[0] var assignedId = apiResponse.mutationResults[0].key.path[0].id console.log(assignedId) })
I'm not following your "WTF?" example. Can you share more information?
So first, pardon my tone in any case. Coffe + late night. Secon, it turns out it was all my mistakes. It works, just some typos.
ps, we are writing a CMS on Google Cloud, only some of the code is Open Source:
https://github.com/topseed/topseed-bp/blob/master/dserver/ds/ContentDS.jsSounds awesome. And no problem, come back with any questions/bugs/wanted features anytime.
- addedtype: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.
on Mar 7, 2017 - added a commit that references this issue
on Feb 26, 2026 - added a commit that references this issue
on Mar 18, 2026
Version 6 worked in production w/ our team of https://www.npmjs.com/package/@google-cloud/datastore
as documented https://cloud.google.com/datastore/docs/datastore-api-tutorial
For example update or delete by key - things you should be regression testing. The example here:
http://github.com/GoogleCloudPlatform/nodejs-docs-samples don't have even basic operations.
For example var key = datastore.key(['Product', 'Computer']) - the method no longer exists and there are no clues as to how to make a key so that you can do an operation.
And this is all over docs.
And beyond the fatal bugs - is this a serious enterprise project by google? They are billing me for google data store use.