Skip to content

Commit 7e05aab

Browse files
standardized variable naming in code snippets (#143)
1 parent a431914 commit 7e05aab

22 files changed

+69
-69
lines changed

source/code-snippets/crud/arrayFilters.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ async function loadData() {
1212
await client.connect();
1313

1414
const database = client.db("test");
15-
const collection = database.collection("pizza");
15+
const pizza = database.collection("pizza");
1616

17-
await collection.drop();
17+
await pizza.drop();
1818

19-
await collection.insertMany([
19+
await pizza.insertMany([
2020
{
2121
name: "Steve Lobsters",
2222
address: "731 Yexington Avenue",
@@ -64,9 +64,9 @@ async function loadData() {
6464
},
6565
]
6666
}
67-
);
67+
]);
6868

69-
console.log(JSON.stringify(await (await collection.find()).toArray()));
69+
console.log(JSON.stringify(await (await pizza.find()).toArray()));
7070
} finally {
7171
await client.close();
7272
}
@@ -79,19 +79,19 @@ async function runAllArrayElements() {
7979
await client.connect();
8080

8181
const database = client.db("test");
82-
const collection = database.collection("pizza");
82+
const pizza = database.collection("pizza");
8383

84-
console.log(JSON.stringify(await (await collection.find()).toArray()));
84+
console.log(JSON.stringify(await (await pizza.find()).toArray()));
8585

8686
// start allArrayElement example
8787
const query = { "name": "Popeye" };
8888
const updateDocument = {
8989
$push: { "items.$[].toppings": "fresh mozzarella" }
9090
};
91-
const result = await collection.updateOne(query, updateDocument);
91+
const result = await pizza.updateOne(query, updateDocument);
9292
// end allArrayElement example
9393
console.log(result.modifiedCount);
94-
console.log(JSON.stringify(await (await collection.find()).toArray()));
94+
console.log(JSON.stringify(await (await pizza.find()).toArray()));
9595
} finally {
9696
await client.close();
9797
}
@@ -102,19 +102,19 @@ async function runFirstArrayElement() {
102102
await client.connect();
103103

104104
const database = client.db("test");
105-
const collection = database.collection("pizza");
105+
const pizza = database.collection("pizza");
106106

107-
console.log(JSON.stringify(await (await collection.find()).toArray()));
107+
console.log(JSON.stringify(await (await pizza.find()).toArray()));
108108

109109
// start firstArrayElement example
110110
const query = { name: "Steve Lobsters", "items.type": "pizza" };
111111
const updateDocument = {
112112
$set: { "items.$.size": "extra large" }
113113
};
114-
const result = await collection.updateOne(query, updateDocument);
114+
const result = await pizza.updateOne(query, updateDocument);
115115
// end firstArrayElement example
116116
console.log(result.modifiedCount);
117-
console.log(JSON.stringify(await (await collection.find()).toArray()));
117+
console.log(JSON.stringify(await (await pizza.find()).toArray()));
118118
} finally {
119119
await client.close();
120120
}
@@ -126,9 +126,9 @@ async function arrayFiltersOne() {
126126
await client.connect();
127127

128128
const database = client.db("test");
129-
const collection = database.collection("pizza");
129+
const pizza = database.collection("pizza");
130130

131-
console.log(JSON.stringify(await (await collection.find()).toArray()));
131+
console.log(JSON.stringify(await (await pizza.find()).toArray()));
132132

133133
// start arrayFiltersOne example
134134
const query = { name: "Steve Lobsters" };
@@ -142,11 +142,11 @@ async function arrayFiltersOne() {
142142
}]
143143
};
144144

145-
const result = await collection.updateMany(query, updateDocument, options);
145+
const result = await pizza.updateMany(query, updateDocument, options);
146146
// end arrayFiltersOne example
147147

148148
console.log(result.modifiedCount);
149-
console.log(JSON.stringify(await (await collection.find()).toArray()));
149+
console.log(JSON.stringify(await (await pizza.find()).toArray()));
150150
} finally {
151151
await client.close();
152152
}
@@ -157,9 +157,9 @@ async function arrayFiltersTwo() {
157157
await client.connect();
158158

159159
const database = client.db("test");
160-
const collection = database.collection("pizza");
160+
const pizza = database.collection("pizza");
161161

162-
console.log(JSON.stringify(await (await collection.find()).toArray()));
162+
console.log(JSON.stringify(await (await pizza.find()).toArray()));
163163

164164
// start arrayFiltersTwo example
165165
const query = { name: "Steve Lobsters" };
@@ -174,11 +174,11 @@ async function arrayFiltersTwo() {
174174
},
175175
],
176176
};
177-
const result = await collection.updateOne(query, updateDocument, options);
177+
const result = await pizza.updateOne(query, updateDocument, options);
178178
// end arrayFiltersTwo example
179179
console.log(result.modifiedCount);
180180

181-
collection.insertOne({
181+
pizza.insertOne({
182182
name: "Steve Lobsters",
183183
address: "731 Yexington Avenue",
184184
items: [
@@ -211,7 +211,7 @@ async function arrayFiltersTwo() {
211211
],
212212
});
213213

214-
console.log(JSON.stringify(await (await collection.find()).toArray()));
214+
console.log(JSON.stringify(await (await pizza.find()).toArray()));
215215
} finally {
216216
await client.close();
217217
}

source/code-snippets/crud/startrek.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ async function run() {
100100
await client.connect();
101101

102102
const database = client.db("sample_mflix");
103-
const collection = database.collection("movies");
103+
const movies = database.collection("movies");
104104

105-
await word(collection);
106-
await phrase(collection);
107-
await negation(collection);
108-
await relevance(collection);
105+
await word(movies);
106+
await phrase(movies);
107+
await negation(movies);
108+
await relevance(movies);
109109
} finally {
110110
await client.close();
111111
}

source/code-snippets/crud/theaters.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ async function run() {
6363
await client.connect();
6464

6565
const database = client.db("sample_mflix");
66-
const collection = database.collection("theaters");
66+
const theaters = database.collection("theaters");
6767

68-
await proximity(collection);
69-
await range(collection);
68+
await proximity(theaters);
69+
await range(theaters);
7070
} finally {
7171
await client.close();
7272
}

source/code-snippets/indexes/compound.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async function run() {
1212
await client.connect();
1313

1414
// begin-idx
15-
const db = client.db("sample_mflix");
16-
const movies = db.collection("movies");
15+
const database = client.db("sample_mflix");
16+
const movies = database.collection("movies");
1717

1818
// Create an ascending index on the "type" and "genre" fields
1919
// in the "movies" collection.

source/code-snippets/indexes/geo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async function run() {
1212
await client.connect();
1313

1414
// begin-idx
15-
const db = client.db("sample_mflix");
16-
const movies = db.collection("movies");
15+
const database = client.db("sample_mflix");
16+
const movies = database.collection("movies");
1717

1818
// Create a 2dsphere index on the "location.geo" field in the "theaters" collection.
1919
const result = await movies.createIndex({ "location.geo": "2dsphere" });

source/code-snippets/indexes/multikey.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async function run() {
1212
await client.connect();
1313

1414
// begin-idx
15-
const db = client.db("sample_mflix");
16-
const movies = db.collection("movies");
15+
const database = client.db("sample_mflix");
16+
const movies = database.collection("movies");
1717

1818
// Create a multikey index on the "cast" array field
1919
// in the "movies" collection.

source/code-snippets/indexes/single-field.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async function run() {
1212
await client.connect();
1313

1414
// begin-idx
15-
const db = client.db("sample_mflix");
16-
const movies = db.collection("movies");
15+
const database = client.db("sample_mflix");
16+
const movies = database.collection("movies");
1717

1818
// Create an ascending index on the "title" field in the
1919
// "movies" collection.

source/code-snippets/indexes/text.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async function run() {
1212
await client.connect();
1313

1414
// begin-idx
15-
const db = client.db("sample_mflix");
16-
const movies = db.collection("movies");
15+
const database = client.db("sample_mflix");
16+
const movies = database.collection("movies");
1717

1818
// Create a text index on the "fullplot" field in the
1919
// "movies" collection.

source/code-snippets/indexes/unique.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async function run() {
1212
await client.connect();
1313

1414
// begin-idx
15-
const db = client.db("sample_mflix");
16-
const movies = db.collection("movies");
15+
const database = client.db("sample_mflix");
16+
const movies = database.collection("movies");
1717

1818
// Create a unique index on the "theaterId" field in the "theaters" collection.
1919
const result = await movies.createIndex({ theaterId: 1 }, { unique: true });

source/code-snippets/usage-examples/bulkWrite.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ async function run() {
1111
await client.connect();
1212

1313
const database = client.db("sample_mflix");
14-
const collection = database.collection("theaters");
14+
const theaters = database.collection("theaters");
1515

16-
const result = await collection.bulkWrite([
16+
const result = await theaters.bulkWrite([
1717
{ insertOne:
1818
{
1919
"document": {

0 commit comments

Comments
 (0)