Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore query documents with only collections inside

I have a firestore collection which has some documents inside it. The documents contains only collections not any fields. So when I try to get all documents inside the root collection i got the snapshot size as zero. Is there any way to get the documents which has no fields but has some collection inside it?

My firestore structure is

document structure

You can also see that the id of documents is shown in italics

code for retrieving data

  db.collection("transactions").get()
    .then(snapshot => { 
      console.log(snapshot.size); returns zero
    })
like image 368
suhail c Avatar asked Nov 26 '25 11:11

suhail c


1 Answers

let date = '2017-12-20' //date to be set in doc

db.collection("transactions").doc(date).set({
  //set an empty object for each doc in transaction before your method 
  //of setting data 
  //This will create a field for each doc in transaction
})
.then(()=>{
  //your method of setting data here.
})
//Your query method here.
//Now you will be able to query the docs in collection - transaction.
like image 105
Shivam Singh Avatar answered Nov 29 '25 00:11

Shivam Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!