firebase / firebase/snippets-node

[firestore docs] Question about query name in firestore snippets

Open
#392 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
395
Forks
139
PR merge metrics
No merged PRs in 30d

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)
```typescript
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?
```typescript
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

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.