我正在编写执行以下操作的Firebase云功能:
收听删除评论的评论,该评论存储在“评论”集合下,并且包括“时间”字段,该字段存储admin.firestore.FieldValue.serverTimestamp()返回的时间戳值。
查询另一个集合“ notification”,其中包括有关注释的信息,包括“ time”字段。在这里,我正在尝试按时间戳查询。
问题是,下面的查询将不起作用。如何按时间戳查询Firestore?什么是正确的语法?
exports.comment_deletion = functions.firestore
.document('comments/{commentid}').onDelete((snap,context)=>{
const data=snap.data();
const time=data.time; //This field is created by admin.firestore.FieldValue.serverTimestamp()
//Below query will return empty result...what will be the right syntax to use?
return db.collection('notification').where('time','==',time).get()
.then(querysnapshot=>{
querysnapshot.forEach(doc=>{
return doc.ref.delete();
})
})
})
非常感谢!
答案 0 :(得分:0)
尝试一下:
const time = data.time.toDate();