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 badges
Add a ment  | 

2 Answers 2

Reset to default 7

The 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);

本文标签: