I'm actually trying to find the most efficient way to reduce the number of read in my Firebase app.
Instead of creating a new document for each object, i was thinking about insert each object inside a new field of the same document.
Here is a typical object that i use in my app :
{
"restaurantName" : "The Love story",
"openingTimes" : {"opening" : "9AM", "closing" : "11pm"},
"numberOfReviews" : 2340
}
According to Firebase the limit of size for a document is 1MB, which is enough to put around 2000 object in my case.
By making a snapshot on one single document, i'm able to read all the fields of the document with this path: payload['_document']['proto']['fields']
this.afs.collection('MyCollection').doc('restaurantName').snapshotChanges().subscribe(data => {
console.log('All the fields of my doc = ', payload['_document']['proto']['fields'])
});
This seems to be working fine and only count as 1 document read each time a change occur in the document right ?
This approach is way cheaper than loading X documents, but something tells me that this is not a good practice.
Is there any reasons why i shouldn't go with this approach ?
Thank you