@@ -12,11 +12,11 @@ async function loadData() {
12
12
await client . connect ( ) ;
13
13
14
14
const database = client . db ( "test" ) ;
15
- const collection = database . collection ( "pizza" ) ;
15
+ const pizza = database . collection ( "pizza" ) ;
16
16
17
- await collection . drop ( ) ;
17
+ await pizza . drop ( ) ;
18
18
19
- await collection . insertMany ( [
19
+ await pizza . insertMany ( [
20
20
{
21
21
name : "Steve Lobsters" ,
22
22
address : "731 Yexington Avenue" ,
@@ -64,9 +64,9 @@ async function loadData() {
64
64
} ,
65
65
]
66
66
}
67
- ) ;
67
+ ] ) ;
68
68
69
- console . log ( JSON . stringify ( await ( await collection . find ( ) ) . toArray ( ) ) ) ;
69
+ console . log ( JSON . stringify ( await ( await pizza . find ( ) ) . toArray ( ) ) ) ;
70
70
} finally {
71
71
await client . close ( ) ;
72
72
}
@@ -79,19 +79,19 @@ async function runAllArrayElements() {
79
79
await client . connect ( ) ;
80
80
81
81
const database = client . db ( "test" ) ;
82
- const collection = database . collection ( "pizza" ) ;
82
+ const pizza = database . collection ( "pizza" ) ;
83
83
84
- console . log ( JSON . stringify ( await ( await collection . find ( ) ) . toArray ( ) ) ) ;
84
+ console . log ( JSON . stringify ( await ( await pizza . find ( ) ) . toArray ( ) ) ) ;
85
85
86
86
// start allArrayElement example
87
87
const query = { "name" : "Popeye" } ;
88
88
const updateDocument = {
89
89
$push : { "items.$[].toppings" : "fresh mozzarella" }
90
90
} ;
91
- const result = await collection . updateOne ( query , updateDocument ) ;
91
+ const result = await pizza . updateOne ( query , updateDocument ) ;
92
92
// end allArrayElement example
93
93
console . log ( result . modifiedCount ) ;
94
- console . log ( JSON . stringify ( await ( await collection . find ( ) ) . toArray ( ) ) ) ;
94
+ console . log ( JSON . stringify ( await ( await pizza . find ( ) ) . toArray ( ) ) ) ;
95
95
} finally {
96
96
await client . close ( ) ;
97
97
}
@@ -102,19 +102,19 @@ async function runFirstArrayElement() {
102
102
await client . connect ( ) ;
103
103
104
104
const database = client . db ( "test" ) ;
105
- const collection = database . collection ( "pizza" ) ;
105
+ const pizza = database . collection ( "pizza" ) ;
106
106
107
- console . log ( JSON . stringify ( await ( await collection . find ( ) ) . toArray ( ) ) ) ;
107
+ console . log ( JSON . stringify ( await ( await pizza . find ( ) ) . toArray ( ) ) ) ;
108
108
109
109
// start firstArrayElement example
110
110
const query = { name : "Steve Lobsters" , "items.type" : "pizza" } ;
111
111
const updateDocument = {
112
112
$set : { "items.$.size" : "extra large" }
113
113
} ;
114
- const result = await collection . updateOne ( query , updateDocument ) ;
114
+ const result = await pizza . updateOne ( query , updateDocument ) ;
115
115
// end firstArrayElement example
116
116
console . log ( result . modifiedCount ) ;
117
- console . log ( JSON . stringify ( await ( await collection . find ( ) ) . toArray ( ) ) ) ;
117
+ console . log ( JSON . stringify ( await ( await pizza . find ( ) ) . toArray ( ) ) ) ;
118
118
} finally {
119
119
await client . close ( ) ;
120
120
}
@@ -126,9 +126,9 @@ async function arrayFiltersOne() {
126
126
await client . connect ( ) ;
127
127
128
128
const database = client . db ( "test" ) ;
129
- const collection = database . collection ( "pizza" ) ;
129
+ const pizza = database . collection ( "pizza" ) ;
130
130
131
- console . log ( JSON . stringify ( await ( await collection . find ( ) ) . toArray ( ) ) ) ;
131
+ console . log ( JSON . stringify ( await ( await pizza . find ( ) ) . toArray ( ) ) ) ;
132
132
133
133
// start arrayFiltersOne example
134
134
const query = { name : "Steve Lobsters" } ;
@@ -142,11 +142,11 @@ async function arrayFiltersOne() {
142
142
} ]
143
143
} ;
144
144
145
- const result = await collection . updateMany ( query , updateDocument , options ) ;
145
+ const result = await pizza . updateMany ( query , updateDocument , options ) ;
146
146
// end arrayFiltersOne example
147
147
148
148
console . log ( result . modifiedCount ) ;
149
- console . log ( JSON . stringify ( await ( await collection . find ( ) ) . toArray ( ) ) ) ;
149
+ console . log ( JSON . stringify ( await ( await pizza . find ( ) ) . toArray ( ) ) ) ;
150
150
} finally {
151
151
await client . close ( ) ;
152
152
}
@@ -157,9 +157,9 @@ async function arrayFiltersTwo() {
157
157
await client . connect ( ) ;
158
158
159
159
const database = client . db ( "test" ) ;
160
- const collection = database . collection ( "pizza" ) ;
160
+ const pizza = database . collection ( "pizza" ) ;
161
161
162
- console . log ( JSON . stringify ( await ( await collection . find ( ) ) . toArray ( ) ) ) ;
162
+ console . log ( JSON . stringify ( await ( await pizza . find ( ) ) . toArray ( ) ) ) ;
163
163
164
164
// start arrayFiltersTwo example
165
165
const query = { name : "Steve Lobsters" } ;
@@ -174,11 +174,11 @@ async function arrayFiltersTwo() {
174
174
} ,
175
175
] ,
176
176
} ;
177
- const result = await collection . updateOne ( query , updateDocument , options ) ;
177
+ const result = await pizza . updateOne ( query , updateDocument , options ) ;
178
178
// end arrayFiltersTwo example
179
179
console . log ( result . modifiedCount ) ;
180
180
181
- collection . insertOne ( {
181
+ pizza . insertOne ( {
182
182
name : "Steve Lobsters" ,
183
183
address : "731 Yexington Avenue" ,
184
184
items : [
@@ -211,7 +211,7 @@ async function arrayFiltersTwo() {
211
211
] ,
212
212
} ) ;
213
213
214
- console . log ( JSON . stringify ( await ( await collection . find ( ) ) . toArray ( ) ) ) ;
214
+ console . log ( JSON . stringify ( await ( await pizza . find ( ) ) . toArray ( ) ) ) ;
215
215
} finally {
216
216
await client . close ( ) ;
217
217
}
0 commit comments