Firestore / Firebase云功能:按时间戳查询?

时间:2020-07-02 08:57:24

标签: firebase google-cloud-firestore

我正在编写执行以下操作的Firebase云功能:

  1. 收听删除评论的评论,该评论存储在“评论”集合下,并且包括“时间”字段,该字段存储admin.firestore.FieldValue.serverTimestamp()返回的时间戳值。

  2. 查询另一个集合“ 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();
         })
     })
 })

非常感谢!

1 个答案:

答案 0 :(得分:0)

尝试一下:

const time = data.time.toDate();
相关问题