How to set firestore document fields with non null

2019-08-17 02:20发布

I am trying to set non-null values to a document in Firestore. There is a way to use Java map object to do this. Fields under custom objects in Cloud Firestore have null value. How to avoid this?The same approach using node js does not seem to work .

Here is my code snippet:

var map = new Map();
map.set('userName', 'hellokitty');

return db.collection('users').doc(uid)
  .set(map)
  .catch(error => {
  throw new functions.https.HttpsError('unknown', error.message, error);
})

This code returns the following error message:

Error: Argument "data" is not a valid Document. Input is not a plain JavaScript object.

Does firestore supports use of javascript map objects? Is there anything I am missing here?

1条回答
Animai°情兽
2楼-- · 2019-08-17 02:50

Just use a regular JavaScript object with properties that describe the document.

const data = {};
data.userName = 'hellokitty';
db.collection('users').doc(uid).set(data);

See the documentation.

查看更多
登录 后发表回答