Home > other >  Unable to perform a Firebase query on a timestamp and receiving an empty body in response
Unable to perform a Firebase query on a timestamp and receiving an empty body in response

Time:08-21

Can someone explain to me why I am not able to perform a simple Firebase query checking for a specific timestamp in a subcollection? The code below works if I try to retrieve the whole document, but if I add the where query it just returns a 200 response with an empty body. I have also tried to replace db.collection with db.collectionGroup and in this case I get a 500 response with the following message Collection IDs must not contain '/'.

Here you can see how I have structured my data and my code:

enter image description here

try {
     const reference = db.collection(`/data/10546781/history`).where("timestamp", "==", 1659559179735)
        
     const document = await reference.get()
        
     res.status(200).json(document.forEach(doc => {
         doc.data()
         console.log(doc.data())
     }))
        
} catch(error) {
    res.status(500).json(error)
    console.log(error)
};

CodePudding user response:

It seems you are looking for enter image description here

  • Related