admin管理员组文章数量:1296432
When I do this in my node.js in firebase cloud functions:
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
});
I get the following error in the logs:
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").
I have checked the documentation here but the only map-related example given seems to deal with updating nested fields. I want to create a map and easily set a field in a firestore document to the contents of this map.
I am new to both node.js and firestore. Thanks in advance for the assistance.
When I do this in my node.js in firebase cloud functions:
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
});
I get the following error in the logs:
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").
I have checked the documentation here https://firebase.google./docs/firestore/manage-data/add-data but the only map-related example given seems to deal with updating nested fields. I want to create a map and easily set a field in a firestore document to the contents of this map.
I am new to both node.js and firestore. Thanks in advance for the assistance.
Share Improve this question edited Feb 19, 2020 at 6:24 Doug Stevenson 318k36 gold badges454 silver badges472 bronze badges asked Feb 19, 2020 at 6:11 ericgithinjiericgithinji 3554 silver badges12 bronze badges2 Answers
Reset to default 7The Firestore SDK for node doesn't support ES6 Map objects. You need to use a normal JavaScript object to build a Firestore map type field.
const o = {
name: 'foo',
description 'helloworld'
}
documentRef.update({
some_field: o
});
As Doug Steven said, it doesn't support map, you can convert your map to plain JS object by:
const updateObj = Object.fromEntries(yourMap);
then pass it to update
documentRef.update(updateObj);
本文标签:
版权声明:本文标题:javascript - Is it possible to update a field of type map in firestore from firebase cloud functions node.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741618835a2388687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论