Javascript Firestore中的数据未更新
这里有一个Javascript Firestore中的数据未更新,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,这里有一个javascript函数,打算在FireStore上执行更新,但该函数不起作用 如果有人能看到代码中的问题,我会更高兴 function makeUpdate(key,name) { let theCollection = db.collection("InformationList"), infoUnit = theCollection.doc(key).get().then(function(doc) { if (doc.exists) {
javascript
函数,打算在FireStore
上执行更新,但该函数不起作用
如果有人能看到代码中的问题,我会更高兴
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);
});
}
除了不执行预期的更新之外,它还在日志中打印三条消息:
- infoUnit-name-:一些名称
- 信息单元-电话:一些电话号码
- 获取文档时出错(在makeUpdate中)
从中我可以看出,数据库中找到了一条预期的记录。但同时发生未知错误。在
doc
上没有update()
方法(它是一个对象)。DocumentSnapshot只包含从get()
读取的数据。如果要将数据写回文档,则需要使用一个对象,可能与调用collection.doc(key)时得到的对象相同。doc
上没有update()
方法(它是一个对象)。DocumentSnapshot只包含从get()
读取的数据。如果要将数据写回文档,需要使用一个对象,可能与调用collection.doc(key)时得到的对象相同,没有一种方法叫做update()
,可以在doc
对象本身上调用
您必须使用从
doc.ref
获取的set()
方法来更新引用。没有名为update()
的方法,您可以在doc
对象本身上调用该方法
您必须使用从
doc.ref
获取的set()
方法来更新引用。这就是我更新数据的方式
await db
.collection('collectionName')
.doc('documentId')
.update({
name: "Updated Name",
telephone: "0000000000"
});
您需要知道文档id,并且可以像这样更新您的值。这就是我更新数据的方式
await db
.collection('collectionName')
.doc('documentId')
.update({
name: "Updated Name",
telephone: "0000000000"
});
您需要知道文档id,并且可以像这样更新您的值