【发布时间】:2020-01-21 10:43:08
【问题描述】:
我正在使用云功能来检查特定文档是否存在,但它不起作用。即使有也找不到文件。代码如下:
exports.onUserAppCreated = functions.firestore.document('users/{userId}/first_col/{colId}')
.onCreate((snap, context) => {
const data = snap.data();
const colId = data.colId;
console.log(colId);
var docRef = db.collection('users/{userId}/somecollection');
let query = docRef.where('colId', '==', colId).get().then(doc => {
if (doc.exists) {
console.log("Document data:", doc.data());
let tracksRef = db.collection('users/{userId}/othercolllection');
tracksRef.where('otherId', '==', colId).get()
.then(transSnapshot => {
if (!transSnapshot.exists) {
transSnapshot.ref.set({
otherId: colId,
time:admin.firestore.FieldValue.serverTimestamp()
});
}
return transSnapshot;
}).catch(error => {
console.log(error);
//response.status(500).send(error);
})
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
return;
}
return doc;
}).catch(function(error) {
console.log("Error getting document:", error);
});
我在这里做错了吗?
【问题讨论】:
标签: node.js firebase google-cloud-firestore google-cloud-functions