【发布时间】:2019-11-25 12:16:13
【问题描述】:
我正在尝试从 Firestore 文档中删除字段,但没有成功。
我已经搜索了我收到的错误消息,但我可以找到几页我已经在做的事情的链接。我确信这很简单,但我现在不知所措。
const Firestore = require('@google-cloud/firestore');
const admin = require('firebase-admin');
const FieldValue = admin.firestore.FieldValue;
const firestore = new Firestore({
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
});
const settings = {timestampsInSnapshots: true};
firestore.settings(settings);
var updateDoc = firestore.collection('XXXXXXXX').doc('XXXXXXX').update({
fieldToBeDeleted: FieldValue.delete()
});
我希望该字段被删除,但我收到以下错误消息:
Error: Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Argument "dataOrField" is not a valid Document. Couldn't serialize object of type "DeleteTransform". Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the 'new' operator).
at WriteBatch.update (XXXXXXXXXX\node_modules\@google-cloud\firestore\build\src\write-batch.js:359:23)
at DocumentReference.update (XXXXXXXXXX\node_modules\@google-cloud\firestore\build\src\reference.js:387:14)
at Object.<anonymous> (XXXXXXXXXX)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
【问题讨论】:
-
您似乎在混合使用 Firebase Admin SDK 和 Cloud SDK。尝试只使用其中一个符号,而不是同时使用两个符号。您使用的是 Cloud SDK 中的
Firestore,但使用的是管理 SDK 中的FieldValue.delete()。 -
道格做到了。谢谢您的帮助。我从顶部删除了 2 行管理 SDK 内容,并将删除行更改为“fieldToBeDeleted: Firestore.FieldValue.delete()”
标签: javascript node.js firebase google-cloud-platform google-cloud-firestore