Skip to content

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

Description

@binarygondola

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions