Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firestore docs] Question about query name in firestore snippets #392

Open
binarygondola opened this issue Mar 1, 2025 · 0 comments
Open

Comments

@binarygondola
Copy link

const allCapitalsRes = citiesRef.where('capital', '==', true);

in simpleQuery function, reference to a collection is named citiesRef (1) and query on this ref is named queryRef (2) - both with ref at the end. Only the result of the query is named res (3)

async function simpleQuery(db) {
  // Create a reference to the cities collection
  const citiesRef = db.collection('cities'); // (1)

  // Create a query against the collection
  const queryRef = citiesRef.where('state', '==', 'CA'); // (2)
  // [END firestore_query_filter_eq_string]

  const res = await queryRef.get(); // (3)
  res.forEach(doc => {
    console.log(doc.id, ' => ', doc.data());
  });
}

however in queryAndFilter function we have a query on a ref that ends with a res in the variable name (1). Shouldn't it be called allCapitalsRef? What is the proper naming convention?

async function queryAndFilter(db) {
  // Create a reference to the cities collection
  const citiesRef = db.collection('cities');

  // Create a query against the collection
  const allCapitalsRes = citiesRef.where('capital', '==', true); // (1)
 // ...rest of the function
}

The code is provided at https://firebase.google.com/docs/firestore/query-data/queries#simple_queries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant