[firestore docs] Question about query name in firestore snippets

Open
#392 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
35/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
documentation

Research direction

Inspect firestore/main/index.js around simpleQuery and queryAndFilter, then compare the linked Firestore query documentation. Determine the naming convention intended for collection references, query objects, and query results; the work is done when the snippet and linked documentation use consistent, agreed naming.

Written by the indexing model from the issue text.

Description

https://github.com/firebase/snippets-node/blob/cccc005f6ba6d3895d1b380215bf54c148dce3fa/firestore/main/index.js#L590

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

Dominant language
JavaScript
Stars
395
Forks
139
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/snippets-node

All issues in firebase/snippets-node

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.