【问题标题】:Firestore/Firebase Cloud Functions: Query by timestamp?Firestore/Firebase Cloud Functions:按时间戳查询?
【发布时间】:2020-10-22 20:03:35
【问题描述】:

我正在编写一个 Firebase 云函数,它执行以下操作:

  1. 监听删除评论,该评论存储在“cmets”集合下,包含“time”字段,该字段存储由 admin.firestore.FieldValue.serverTimestamp() 返回的时间戳值。

  2. 查询另一个集合'notification',其中包含有关cmets的信息,包括'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();
         })
     })
 })

提前非常感谢!

【问题讨论】:

标签: firebase google-cloud-firestore


【解决方案1】:

试试这个:

const time = data.time.toDate();

【讨论】:

    猜你喜欢
    • 2018-08-18
    • 2021-02-24
    • 1970-01-01
    • 2021-11-18
    • 2019-02-14
    • 2020-04-17
    • 2020-12-26
    • 2021-05-30
    • 2018-03-20
    相关资源
    最近更新 更多