Skip to content

Commit ffe0cc8

Browse files
authored
DOCSP-32718: deletemany UE code comments (#754)
* DOCSP-32718: deletemany UE code comments * add ts code * CC comments js file * CC comments ts file
1 parent f09e867 commit ffe0cc8

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1+
/* Delete multiple documents */
2+
3+
// Import the MongoClient type from the mongodb package.
14
import { MongoClient } from "mongodb";
25

36
// Replace the uri string with your MongoDB deployment's connection string.
47
const uri = "<connection string uri>";
58

9+
// Create a new client and connect to MongoDB.
610
const client = new MongoClient(uri);
711

812
async function run() {
913
try {
1014
const database = client.db("sample_mflix");
1115
const movies = database.collection("movies");
12-
// Query for all movies with a title containing the string "Santa"
13-
const query = { title: { $regex: "Santa" } };
1416

17+
/* Delete all documents that match the specified regular
18+
expression in the title field from the "movies" collection */
19+
const query = { title: { $regex: "Santa" } };
1520
const result = await movies.deleteMany(query);
21+
22+
// Print the number of deleted documents
1623
console.log("Deleted " + result.deletedCount + " documents");
1724
} finally {
25+
// Close the client after the operation completes
1826
await client.close();
1927
}
2028
}
29+
// Run the program and print any thrown exceptions
2130
run().catch(console.dir);
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1+
/* Delete multiple documents */
2+
3+
// Import the MongoClient type from the mongodb package
14
import { MongoClient } from "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
47
const uri = "<connection string uri>";
58

9+
// Create a new client and connect to MongoDB
610
const client = new MongoClient(uri);
711

8-
interface Movie {
9-
title: string;
10-
}
11-
1212
async function run() {
1313
try {
1414
const database = client.db("sample_mflix");
15-
const movies = database.collection<Movie>("movies");
15+
const movies = database.collection("movies");
16+
17+
/* Delete all documents that match the specified regular
18+
expression in the title field from the "movies" collection */
1619
const result = await movies.deleteMany({ title: { $regex: "Santa" } });
20+
21+
// Print the number of deleted documents
1722
console.log("Deleted " + result.deletedCount + " documents");
1823
} finally {
24+
// Close the client after the operation completes
1925
await client.close();
2026
}
2127
}
28+
// Run the program and print any thrown exceptions
2229
run().catch(console.dir);

0 commit comments

Comments
 (0)