如何使用JavaScript设置非空值的Firestore文档字段
我正在尝试为Firestore中的文档设置非null值.有一种使用Java映射对象执行此操作的方法.
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 .
这是我的代码段:
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:
错误:参数数据"不是有效的文档.输入不是普通的JavaScript对象.
Error: Argument "data" is not a valid Document. Input is not a plain JavaScript object.
firestore是否支持使用JavaScript地图对象?我在这里想念什么吗?
Does firestore supports use of javascript map objects? Is there anything I am missing here?
只需使用具有描述文档属性的常规JavaScript对象即可.
Just use a regular JavaScript object with properties that describe the document.
const data = {};
data.userName = 'hellokitty';
db.collection('users').doc(uid).set(data);
请参见文档.