Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

413
Views
In Firebase Firestore, is there an advantage to using the docRef pattern that is often shown in the docs?

In the Firestore documentation (and other Firebase docs as well) they tend to set a reference to an item (collection or sometimes document) in a variable, then use that reference to create/update the data on the item.

Here's a copy/paste from the Firestore docs with citiesRef as an example.

var citiesRef = db.collection("cities");

citiesRef.doc("SF").set({
    name: "San Francisco", state: "CA", country: "USA",
    capital: false, population: 860000,
    regions: ["west_coast", "norcal"] });
citiesRef.doc("LA").set({
    name: "Los Angeles", state: "CA", country: "USA",
    capital: false, population: 3900000,
    regions: ["west_coast", "socal"] });

Is there a technical advantage to Firestore in setting it up like this? (Aside from saving the code repetition of the value of the citiesRef variable.)

More specifically, is this saving multiple hits to Firestore or the collection?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

No, this is not saving any write or read hits. The only advantage should be code reusability and readability.

The example you gave will result in two write hits.

about 4 years ago · Juan Pablo Isaza Report

0

More specifically, is this saving multiple hits to Firestore or the collection?

It's all about how you declare the references. Using db.collection() every time instead of declaring such variable won't charge you any extra cost.

You are not charged for just creating a reference to a collection or document. You are charged for read and writes when you use get() or set() respectively or any other operations that actually read from Firestore or write data.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!