admin管理员组文章数量:1391943
Here is a javascript
function intending to perform an update on FireStore
, which does not work.
I will be more that happy if anyone can see an issue in the code.
function makeUpdate(key,name) {
let theCollection = db.collection("InformationList"),
infoUnit = theCollection.doc(key).get().then(function(doc) {
if (doc.exists) {
console.log("infoUnit -name-:" + doc.get("name"));
console.log("infoUnit -telephone-:" + doc.get("telephone"));
let updateDico = {};
updateDico["name"] = name;
doc.update(updateDico);
} else {
console.log("embassyUpdate --> No such document!");
}
}).catch(err => {
console.log("Error getting documents (in makeUpdate)", err);
});
}
Apart from the fact that it does not perform the expected update, it prints three messages in the logs:
- infoUnit -name-: some name
- infoUnit -telephone-: some telephone number
- Error getting documents (in makeUpdate)
From that I can see that a record is found in the database as expected. But at the same time an unknown error occurs.
Here is a javascript
function intending to perform an update on FireStore
, which does not work.
I will be more that happy if anyone can see an issue in the code.
function makeUpdate(key,name) {
let theCollection = db.collection("InformationList"),
infoUnit = theCollection.doc(key).get().then(function(doc) {
if (doc.exists) {
console.log("infoUnit -name-:" + doc.get("name"));
console.log("infoUnit -telephone-:" + doc.get("telephone"));
let updateDico = {};
updateDico["name"] = name;
doc.update(updateDico);
} else {
console.log("embassyUpdate --> No such document!");
}
}).catch(err => {
console.log("Error getting documents (in makeUpdate)", err);
});
}
Apart from the fact that it does not perform the expected update, it prints three messages in the logs:
- infoUnit -name-: some name
- infoUnit -telephone-: some telephone number
- Error getting documents (in makeUpdate)
From that I can see that a record is found in the database as expected. But at the same time an unknown error occurs.
Share Improve this question edited Oct 26, 2018 at 10:28 Doug Stevenson 319k36 gold badges456 silver badges473 bronze badges asked Oct 26, 2018 at 10:21 MichelMichel 11.8k21 gold badges102 silver badges219 bronze badges3 Answers
Reset to default 3There is no update()
method on doc
(which a DocumentSnapshot object). A DocumentSnapshot just contains the data read from get()
. If you want to write data back into a document, you'll need to use a DocumentReference object, probably the same one you got when you called theCollection.doc(key)
.
There is no such method called update()
which you can invoke on doc
DataSnapshot object itself.
You'll have to use the set()
method on the Document Reference which you get from doc.ref
to update the reference.
This is how I've updated my data.
await db
.collection('collectionName')
.doc('documentId')
.update({
name: "Updated Name",
telephone: "0000000000"
});
You need to know document id and you can update your value like this.
本文标签: javascriptData in Firestore not updatingStack Overflow
版权声明:本文标题:javascript - Data in Firestore not updating - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744701632a2620596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论