Skip to content

Commit e81f4c9

Browse files
committed
merge conflict
2 parents d67f791 + f3ad211 commit e81f4c9

File tree

18 files changed

+1186
-40
lines changed

18 files changed

+1186
-40
lines changed

source/code-snippets/crud/bulk.js

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
const {
2+
MongoClient,
3+
ObjectId
4+
} = require('mongodb');
5+
6+
const uri = '<connection string>'; // Add your MongoDB connection string here
7+
8+
(async () => {
9+
const client = new MongoClient(uri);
10+
11+
try {
12+
await client.connect();
13+
14+
const database = client.db('sample_mflix');
15+
const movies = database.collection('movies');
16+
17+
// begin-insert-coll
18+
const insertModels = [{
19+
insertOne: {
20+
document: {
21+
title: "The Favourite",
22+
year: 2018,
23+
rated: "R",
24+
released: "2018-12-21"
25+
}
26+
}
27+
}, {
28+
insertOne: {
29+
document: {
30+
title: "I, Tonya",
31+
year: 2017,
32+
rated: "R",
33+
released: "2017-12-08"
34+
}
35+
}
36+
}];
37+
38+
const insertResult = await movies.bulkWrite(insertModels);
39+
console.log(`Inserted documents: ${insertResult.insertedCount}`);
40+
// end-insert-coll
41+
42+
// begin-insert-client
43+
const clientInserts = [{
44+
namespace: "sample_mflix.movies",
45+
name: "insertOne",
46+
document: {
47+
title: "The Favourite",
48+
year: 2018,
49+
rated: "R",
50+
released: "2018-12-21"
51+
}
52+
}, {
53+
namespace: "sample_mflix.movies",
54+
name: "insertOne",
55+
document: {
56+
title: "I, Tonya",
57+
year: 2017,
58+
rated: "R",
59+
released: "2017-12-08"
60+
}
61+
}, {
62+
namespace: "sample_mflix.users",
63+
name: "insertOne",
64+
document: {
65+
name: "Brian Schwartz",
66+
67+
}
68+
}];
69+
70+
const clientInsertRes = await client.bulkWrite(clientInserts);
71+
console.log(`Inserted documents: ${clientInsertRes.insertedCount}`);
72+
// end-insert-client
73+
74+
await movies.insertMany(docs);
75+
76+
// begin-replace-coll
77+
const replaceOperations = [{
78+
replaceOne: {
79+
filter: {
80+
title: "The Dark Knight"
81+
},
82+
replacement: {
83+
title: "The Dark Knight Rises",
84+
year: 2012,
85+
rating: "PG-13"
86+
},
87+
upsert: false
88+
}
89+
}, {
90+
replaceOne: {
91+
filter: {
92+
title: "Inception"
93+
},
94+
replacement: {
95+
title: "Inception Reloaded",
96+
year: 2010,
97+
rating: "PG-13"
98+
},
99+
upsert: false
100+
}
101+
}];
102+
103+
const replaceResult = await movies.bulkWrite(replaceOperations);
104+
console.log(`Modified documents: ${replaceResult.modifiedCount}`);
105+
// end-replace-coll
106+
107+
// begin-replace-client
108+
const clientReplacements = [{
109+
namespace: "sample_mflix.movies",
110+
name: "replaceOne",
111+
filter: {
112+
title: "The Dark Knight"
113+
},
114+
replacement: {
115+
title: "The Dark Knight Rises",
116+
year: 2012,
117+
rating: "PG-13"
118+
}
119+
}, {
120+
namespace: "sample_mflix.movies",
121+
name: "replaceOne",
122+
filter: {
123+
title: "Inception"
124+
},
125+
replacement: {
126+
title: "Inception Reloaded",
127+
year: 2010,
128+
rating: "PG-13"
129+
}
130+
}, {
131+
namespace: "sample_mflix.users",
132+
name: "replaceOne",
133+
filter: {
134+
name: "April Cole"
135+
},
136+
replacement: {
137+
name: "April Franklin",
138+
139+
}
140+
}];
141+
142+
const clientReplaceRes = await client.bulkWrite(clientReplacements);
143+
console.log(`Modified documents: ${clientReplaceRes.modifiedCount}`);
144+
// end-replace-client
145+
146+
// begin-update-coll
147+
const updateOperations = [{
148+
updateOne: {
149+
filter: {
150+
title: "Interstellar"
151+
},
152+
update: {
153+
$set: {
154+
title: "Interstellar Updated",
155+
genre: "Sci-Fi Adventure"
156+
}
157+
},
158+
upsert: true
159+
}
160+
}, {
161+
updateMany: {
162+
filter: {
163+
rated: "PG-13"
164+
},
165+
update: {
166+
$set: {
167+
rated: "PG-13 Updated",
168+
genre: "Updated Genre"
169+
}
170+
}
171+
}
172+
}];
173+
174+
const updateResult = await movies.bulkWrite(updateOperations);
175+
console.log(`Modified documents: ${updateResult.modifiedCount}`);
176+
// end-update-coll
177+
178+
// begin-update-client
179+
const clientUpdates = [{
180+
namespace: "sample_mflix.movies",
181+
name: "updateMany",
182+
filter: {
183+
rated: "PG-13"
184+
},
185+
update: {
186+
$set: {
187+
rated: "PG-13 Updated",
188+
genre: "Updated Genre"
189+
}
190+
},
191+
upsert: false
192+
}, {
193+
namespace: "sample_mflix.users",
194+
name: "updateOne",
195+
filter: {
196+
name: "Jon Snow"
197+
},
198+
update: {
199+
$set: {
200+
name: "Aegon Targaryen",
201+
202+
}
203+
},
204+
upsert: false
205+
}];
206+
const clientUpdateRes = await client.bulkWrite(clientUpdates);
207+
console.log(`Modified documents: ${clientUpdateRes.modifiedCount}`);
208+
// end-update-client
209+
210+
// begin-delete-coll
211+
const deleteOperations = [{
212+
deleteOne: {
213+
filter: {
214+
title: "Dunkirk"
215+
}
216+
}
217+
}, {
218+
deleteMany: {
219+
filter: {
220+
rated: "R"
221+
}
222+
}
223+
}];
224+
225+
const deleteResult = await movies.bulkWrite(deleteOperations);
226+
console.log(`Deleted documents: ${deleteResult.deletedCount}`);
227+
// end-delete-coll
228+
229+
// begin-delete-client
230+
const clientDeletes = [{
231+
namespace: "sample_mflix.movies",
232+
name: "deleteMany",
233+
filter: {
234+
rated: "R"
235+
}
236+
}, {
237+
namespace: "sample_mflix.users",
238+
name: "deleteOne",
239+
filter: {
240+
241+
}
242+
}];
243+
244+
const clientDeleteRes = await client.bulkWrite(clientDeletes);
245+
console.log(`Deleted documents: ${clientDeleteRes.deletedCount}`);
246+
// end-delete-client
247+
248+
console.log("Operations completed successfully.");
249+
} finally {
250+
await client.close();
251+
}
252+
})();

source/code-snippets/indexes/text.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ async function run() {
1717
// Create a text index on the "title" and "body" fields
1818
const result = await myColl.createIndex(
1919
{ title: "text", body: "text" },
20-
{ default_language: "english" },
21-
{ weights: { body: 10, title: 3 } }
20+
{
21+
default_language: "english",
22+
weights: { body: 10, title: 3 }
23+
}
2224
);
2325
// end-idx
2426
console.log(`Index created: ${result}`);

source/faq.txt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,9 @@ What Is the Difference Between "connectTimeoutMS", "socketTimeoutMS" and "maxTim
122122
<node-connection-options>` that sets the time, in milliseconds,
123123
for an individual connection from your connection pool to
124124
establish a TCP connection to the {+mdb-server+} before
125-
timing out.
126-
127-
.. tip::
128-
129-
To modify the allowed time for `MongoClient.connect <{+api+}/classes/MongoClient.html#connect>`__ to establish a
130-
connection to a {+mdb-server+}, use the ``serverSelectionTimeoutMS`` option instead.
125+
timing out. To modify the allowed time for
126+
`MongoClient.connect <{+api+}/classes/MongoClient.html#connect>`__ to establish a
127+
connection to a {+mdb-server+}, use the ``serverSelectionTimeoutMS`` option instead.
131128

132129
**Default:** 30000
133130
* - **socketTimeoutMS**
@@ -170,9 +167,7 @@ What Happens to Running Operations if the Client Disconnects?
170167

171168
Starting in {+mdb-server+} version 4.2, the server terminates
172169
running operations such as aggregations and find operations if the
173-
client disconnects. To see a full list of operations affected by this
174-
behavior, see the :manual:`Server version 4.2 release notes
175-
</release-notes/4.2/#client-disconnection>` in the Server manual.
170+
client disconnects.
176171

177172
Other operations, such as write operations, continue to run on the
178173
{+mdb-server+} even if the client disconnects. This behavior can cause data

source/fundamentals/authentication/mechanisms.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,29 @@ The driver checks for your credentials in the following sources in order:
229229

230230
export AWS_WEB_IDENTITY_TOKEN_FILE=<absolute path to file containing your OIDC token>
231231

232-
After you've set the preceding environment variable, specify the ``MONGODB-AWS``
232+
AWS recommends using regional AWS STS endpoints instead of global
233+
endpoints to reduce latency, build-in redundancy, and increase session token validity.
234+
To set the AWS region, set `AWS_REGION <https://docs.aws.amazon.com/sdkref/latest/guide/feature-region.html>`__
235+
and `AWS_STS_REGIONAL_ENDPOINTS <https://docs.aws.amazon.com/sdkref/latest/guide/feature-sts-regionalized-endpoints.html>`__
236+
as environment variables, as shown in the following example:
237+
238+
.. code-block:: bash
239+
240+
export AWS_STS_REGIONAL_ENDPOINTS=regional // Enables regional endpoints
241+
export AWS_REGION=us-east-1 // Sets your AWS region
242+
243+
If both these environment variables aren't set, the default region is
244+
``us-east-1``. For a list of available AWS regions, see the
245+
`Regional Endpoints <https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints>`__
246+
section of the AWS Service Endpoints reference in the AWS documentation.
247+
248+
.. warning:: Consult your SDK's Documentation for Setting an AWS Region
249+
250+
You cannot set your AWS region with environment variables for all SDKs,
251+
as in the above example. See your SDK's specific documentation for
252+
configuring an AWS region.
253+
254+
After you've set the preceding environment variables, specify the ``MONGODB-AWS``
233255
authentication mechanism in your connection string as shown in the following example:
234256

235257
.. literalinclude:: /code-snippets/authentication/aws-env-variable.js

source/fundamentals/connection/connection-options.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ parameters of the connection URI to specify the behavior of the client.
5353
- ``null``
5454
- Specifies the database that connections authenticate against.
5555

56+
* - **autoSelectFamily**
57+
- boolean
58+
- ``true``
59+
- If set to ``true``, the socket attempts to connect to IPv6 and IPv4 addresses
60+
until a connection is established. If available, the driver will select
61+
the first IPv6 address.
62+
63+
* - **autoSelectFamilyAttemptTimeout**
64+
- non-negative integer
65+
- ``null``
66+
- Specifies the amount of time in milliseconds to wait for a connection
67+
attempt to finish before trying the next address when using the
68+
``autoSelectFamily`` option. If set to a positive integer less than ``10``,
69+
the value ``10`` is used instead.
70+
5671
* - **compressors**
5772
- comma separated list of strings, for example, "snappy,zlib,zstd"
5873
- ``null``
@@ -321,6 +336,8 @@ parameters of the connection URI to specify the behavior of the client.
321336
- ``0``
322337
- Specifies the amount of time, in milliseconds, spent attempting to check out a connection
323338
from a server's connection pool before timing out.
339+
340+
``0`` signifies no timeout.
324341

325342
* - **wTimeoutMS**
326343
- non-negative integer

source/fundamentals/connection/network-compression.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ by specifying the algorithms in one of two ways:
5555
.. tab:: MongoClientOptions
5656
:tabid: mongoclientoptions
5757

58-
To enable compression using the `MongoClientOptions <{+api+}/api/global.html#MongoClientOptions>`__,
58+
To enable compression using the `MongoClientOptions <{+api+}/interfaces/MongoClientOptions.html>`__,
5959
pass the ``compressors`` option and the compression
6060
algorithm you want to use. You can specify one or more compression
6161
algorithms, separating them with commas:

source/fundamentals/crud/write-operations.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ Write Operations
1515
Modify </fundamentals/crud/write-operations/modify>
1616
Update Arrays </fundamentals/crud/write-operations/embedded-arrays>
1717
Upsert </fundamentals/crud/write-operations/upsert>
18+
Bulk Operations </fundamentals/crud/write-operations/bulk>
1819

1920
- :doc:`/fundamentals/crud/write-operations/insert`
2021
- :doc:`/fundamentals/crud/write-operations/pkFactory`
2122
- :doc:`/fundamentals/crud/write-operations/delete`
2223
- :doc:`/fundamentals/crud/write-operations/modify`
2324
- :doc:`/fundamentals/crud/write-operations/embedded-arrays`
2425
- :doc:`/fundamentals/crud/write-operations/upsert`
26+
- :doc:`/fundamentals/crud/write-operations/bulk`

0 commit comments

Comments
 (0)