JarsOfJam-Scheduler
JarsOfJam-Scheduler

Reputation: 3149

Firestore: Is it equivalent to chain a document with a subcollection calls, and store a document then store its subcollection?

Are db.document("a").collection("b") and some_var = db.document("a"); some_var_2 = some_var.collection("b") equivalent?

In particular: in both cases, are "a"'s fields retrieved from database and loaded in RAM (especially for the first way)? (in other words: does the first way just retrieve the subcollection without retrieving/loading "a"'s fields?)

Upvotes: 0

Views: 64

Answers (2)

Loheek
Loheek

Reputation: 1985

In both cases, you will only generate document or collection references, so Firestore won't fetch any data until you call a method (such as .get()) on it.

So, there is no difference, but you should use the first way in the case you will need to make operations on the entire collection in addition to the single document.

Upvotes: 1

Doug Stevenson
Doug Stevenson

Reputation: 317467

They are equivalent.

Neither of them actually retrieve any data. They are just creating references to documents. You have to call get() or attach a listener to actually get the data from the documents. You should probably familiarize yourself with the documentation for reading data from Firestore.

Upvotes: 1

Related Questions