File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
source/code-snippets/usage-examples Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 1+ /* Bulk write operation */
2+
3+ // Import MongoClient from the MongoDB node driver package
14const { MongoClient } = require ( "mongodb" ) ;
25
3- // Replace the uri string with your MongoDB deployment's connection string.
6+ // Replace the uri string with your MongoDB deployment's connection string
47const uri = "<connection string uri>" ;
58
69const client = new MongoClient ( uri ) ;
@@ -10,6 +13,7 @@ async function run() {
1013 const database = client . db ( "sample_mflix" ) ;
1114 const theaters = database . collection ( "theaters" ) ;
1215
16+ // Insert a new document into the "theaters" collection
1317 const result = await theaters . bulkWrite ( [
1418 {
1519 insertOne : {
@@ -40,19 +44,22 @@ async function run() {
4044 } ,
4145 } ,
4246 {
47+ // Update documents that match the specified filter
4348 updateMany : {
4449 filter : { "location.address.zipcode" : "44011" } ,
4550 update : { $set : { is_in_ohio : true } } ,
4651 upsert : true ,
4752 } ,
4853 } ,
4954 {
55+ // Delete a document that matches the specified filter
5056 deleteOne : { filter : { "location.address.street1" : "221b Baker St" } } ,
5157 } ,
5258 ] ) ;
53-
59+ // Log the result of the bulk write operation
5460 console . log ( result ) ;
5561 } finally {
62+ // Close the database connection when the operations are completed or if an error occurs
5663 await client . close ( ) ;
5764 }
5865}
You can’t perform that action at this time.
0 commit comments