admin管理员组文章数量:1194134
The following code creates a firestore collection and adds data to it:
function saveID(sender_psid,complete){
let data = new Object();
data.ID = sender_psid;
data.TASK = complete;
data.TIME = new Date();
db.collection('users').add(data);
}
I want to create another function which adds a field to the document at a different time. I have the following function but am getting the error "TypeError: collectionRef.update is not a function"
function saveImage(sender_psid,image) {
let collectionRef = db.collection('users');
collectionRef.update({IMG:image}).then(res => {
console.log(`Document updated at ${res.updateTime}`);
});
}
The following code creates a firestore collection and adds data to it:
function saveID(sender_psid,complete){
let data = new Object();
data.ID = sender_psid;
data.TASK = complete;
data.TIME = new Date();
db.collection('users').add(data);
}
I want to create another function which adds a field to the document at a different time. I have the following function but am getting the error "TypeError: collectionRef.update is not a function"
function saveImage(sender_psid,image) {
let collectionRef = db.collection('users');
collectionRef.update({IMG:image}).then(res => {
console.log(`Document updated at ${res.updateTime}`);
});
}
Share
Improve this question
edited Jan 16, 2019 at 13:47
Cœur
38.7k26 gold badges202 silver badges277 bronze badges
asked Jul 13, 2018 at 21:34
RashikRashik
1,1442 gold badges16 silver badges36 bronze badges
3 Answers
Reset to default 15Build a DocumentReference to the document you want to update, then use the update() method on the DocumentReference to indicate only the fields to be added or changed. Pass it an object with only properties that match the fields to add or change.
According to this documentation, There is a better way
const cityRef = db.collection('cities').doc('BJ');
const res = await cityRef.set({
capital: true
}, { merge: true });
Flutter Example:
var userDoc = Firestore.instance.collection('users').document('replaceIdHere');
userDoc.updateData({'fieldName':'newValue'});
本文标签: javascriptAdd field separately to firestore documentStack Overflow
版权声明:本文标题:javascript - Add field separately to firestore document - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738482540a2089227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论