0
votes

I am writing a Firebase cloud function that does the following:

  1. Listen to deletion of a comment, which is stored under 'comments' collection and includes 'time' field, which stores the timestamp value returned by admin.firestore.FieldValue.serverTimestamp().

  2. Query another collection 'notification', which includes the information about the comments, including the 'time' field. Here, I am trying to query by timestamp.

The problem is, below query will not work. How do I query by timestamp for Firestore? What will be the right syntax to use?

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();
         })
     })
 })

Thanks a lot in advance!

1

1 Answers

0
votes

Try this:

const time = data.time.toDate();