【发布时间】:2020-11-15 15:20:51
【问题描述】:
我一直在我的网站后端实现一个通知系统,当新消息创建时,数据库的结构如下图所示:
但是当创建消息时发生了这个错误:
错误
Error: Value for argument "data" is not a valid Firestore document. Cannot use "undefined" as a Firestore value (found in field "chatId"). If you want to ignore undefined values, enable `ignoreUndefinedProperties`.
at validateUserInput (/workspace/node_modules/@google-cloud/firestore/build/src/serializer.js:271:19)
at Object.validateUserInput (/workspace/node_modules/@google-cloud/firestore/build/src/serializer.js:263:13)
at validateDocumentData (/workspace/node_modules/@google-cloud/firestore/build/src/write-batch.js:590:18)
at WriteBatch.set (/workspace/node_modules/@google-cloud/firestore/build/src/write-batch.js:256:9)
at DocumentReference.set (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:342:14)
at /workspace/index.js:200:68
at processTicksAndRejections (internal/process/task_queues.js:97:5)
索引.js
exports.createNotificationOnFirstMessage=functions.region('europe-west1').firestore.document('/chats/{chatId}/messages/{messageId}')
.onCreate((snapshot)=>{
var recipientArrn = snapshot.data().chatId.split('_');
// recipientArrn is an array of substring, the first is the sender (index 0), the second is the recipient (index 1)
return db.doc(`/users/${recipientArrn[1]}`).get()
.then(doc =>{
if(doc.exists){
return db.doc(`/notifications/${snapshot.id}`).set({
createdAt: new Date().toISOString(),
recipient: recipientArrn[1],
sender: snapshot.data().sender,
type:'message',
read: false,
chatId: doc.chatId,
});
}
})
.catch(err =>{
console.error(err);
});
})
我可以做些什么来解决这个错误?
【问题讨论】:
标签: node.js firebase google-cloud-platform google-cloud-firestore