当我在我的 node.js 中的 firebase 云函数中执行此操作时:
var my_map = new Map();
my_map.set('name','foo');
my_map.set('description','helloworld');
//update the firestore document
let updateDocument = documentRef.update({
some_field: my_map
});
我在日志中收到以下错误:
failed to query incidents Error: Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Value for argument "dataOrField" is not a valid Firestore document. Input is not a plain JavaScript object (found in field "some_field").
我在这里查看了文档 https://firebase.google.com/docs/firestore/manage-data/add-data但给出的唯一与 map 相关的示例似乎处理更新嵌套字段。我想创建一个 map 并轻松地将 Firestore 文档中的一个字段设置为该 map 的内容。
我是 node.js 和 firestore 的新手。提前感谢您的帮助。
最佳答案
Node 的 Firestore SDK 不支持 ES6 Map 对象。您需要使用普通的 JavaScript 对象来构建 Firestore map 类型字段。
const o = {
name: 'foo',
description 'helloworld'
}
documentRef.update({
some_field: o
});
关于javascript - 是否可以从firebase云函数node.js更新firestore中的map类型字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60294077/