Reputation: 28906
Screenshot 1:
At student > 100 > name
, I want to update 'name'
to 'Bar'
.
Screenshot 2:
At student > 100 > exam > english > marks
, I want to update 'marks'
to 50
.
Now, I am able to update them using
var firestore = Firestore.instance;
firestore.document('student/100').updateData({'name': 'Bar'});
firestore.document('student/100/exams/english').updateData({'marks': 50});
Problem:
This code gets called two times:
var ref = firestore.document('student/100');
ref.snapshots().listen((event) {
print('server updated'); // called 2 times
});
Will this be counted as two write? If yes, how can I change it to one write because both the fields belong to same path 'student/100'
?
Upvotes: 0
Views: 51
Reputation: 80914
Will this be counted as two write?
Yes, it will count as two write.
When you use Cloud Firestore, you are charged for the following:
If yes, how can I change it to one write because both the fields belong to same path 'student/100'?
In Firestore, queries are shallow which means when you are writing to a document under a top level collection you cannot access the documents inside the subcollection unless you specificy the path toward that document. Therefore it is not possible to perform one write for both the top level document and the document inside subcollection.
Upvotes: 2