【发布时间】:2022-02-23 13:50:52
【问题描述】:
我在使用 node.js 从 Google Cloud Datastore 中删除实体时遇到问题。我怀疑我错过了一些非常基本的东西,因为这应该不难。
我只按照this documentation获取密钥:
const query = datastore.createQuery('coin').select('__key__');
运行查询:
const [keys] = await datastore.runQuery(query);
根据this documentation 按键删除生成的实体:
datastore.delete(keys);
但我得到“InvalidKey:密钥应至少包含一种。”
如果我在运行查询后立即执行 console.log(keys),则确实有一个看起来是有效类型的关键结果的数组:
[
{
[Symbol(KEY)]: Key {
namespace: undefined,
id: '5083500323536896',
kind: 'coin',
path: [Getter]
}
},
{
[Symbol(KEY)]: Key {
namespace: undefined,
id: '5130717650485248',
kind: 'coin',
path: [Getter]
}
},
etc...
上面不是 .delete() 期望的数组吗?
【问题讨论】:
-
你能分享整个错误的踪迹吗?
-
InvalidKey:密钥至少应包含一种。在 Object.keyToKeyProto (/node_modules/@google-cloud/datastore/build/src/entity.js:974:19) 在 /node_modules/@google-cloud/datastore/build/src/request.js:194:45 在Array.map (
) 在 Datastore.delete (/node_modules/@google- -
cloud/datastore/build/src/request.js:192:37) at /node_modules/@google-cloud/promisify/build/src/index.js:57:28 at new Promise (
) 在 Datastore.wrapper (/node_modules/@google-cloud/promisify/build/src/index.js:42:16) 在 /app.js:103:27 在 processTicksAndRejections (internal/process/task_queues.js :95:5)
标签: node.js google-cloud-platform datastore