I am using google cloud FireStore as a database for our e-commerce mobile application. I am a bit confused about the document read count for firestore documents when we retrieve documents from cloud firestore.
Location of firebase doc: users/123/ This doc contains users information like userId, userName, wishlist, cart, addresses and so. I have used multiple sub-maps to save all user data in a single document to reduce firestore billing costs. Structure of document :
userId:"123",
userName:"Sunil",
addresses : {
address1 : {
"doorNo":"123",
"city" : "Bengaluru"
},
address2 : {
"doorNo":"456",
"city" : "Bengaluru"
},
address3 : {
"doorNo":"789",
"city" : "Bengaluru"
},
wishlistItems:{
item1 : {
"itemId":"1"
},
item2 : {
"itemId":"2"
},
item3 : {
"itemId":"3"
},
item4 : {
"itemId":"4"
},
},
cartItems:{
cartItem1:{
"itemId":"1",
"itemCount":"2",
},
cartItem2:{
"itemId":"2",
"itemCount":"5",
},
cartItem3:{
"itemId":"3",
"itemCount":"7",
},
cartItem1:{
"itemId":"4",
"itemCount":"8",
},
},
},
I retrieve the document as follow: firestore().collection("users").doc("123").get();
My Questions : how many reads will be counted for each retrieval? Will it be only one as I am retrieving only a single document or will it be 12 (as the document is having 11 sub-maps and 1 as normal count)?
Please, help me get clear on this. Thanking you in advance.
CodePudding user response:
Reads are charged on how many documents you get back in the result irrespective of content.
firestore().collection("users").doc("123").get();
The above read will cost only 1 read (that too if the document exists).
firestore().collection("users").where("age", ">=", 10).get();
For example, in above query if 57 docs are matched and returned then you'll be charged 57 reads.
If you have offline persistence enabled and some docs are read from cache, you won't be charged for them.
CodePudding user response:
Since you are reading everything from a single document, it counts as 1 read.