Skip to content

DOCSP-32718: deletemany UE code comments #754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions source/code-snippets/usage-examples/deleteMany.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
/* Delete multiple documents */

// Import the MongoClient type from the mongodb package.
import { MongoClient } from "mongodb";

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

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

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

/* Delete all documents that match the specified regular
expression in the title field from the "movies" collection */
const query = { title: { $regex: "Santa" } };
const result = await movies.deleteMany(query);

// Print the number of deleted documents
console.log("Deleted " + result.deletedCount + " documents");
} finally {
// Close the client after the operation completes
await client.close();
}
}
// Run the program and print any thrown exceptions
run().catch(console.dir);
19 changes: 13 additions & 6 deletions source/code-snippets/usage-examples/deleteMany.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
/* Delete multiple documents */

// Import the MongoClient type from the mongodb package
import { MongoClient } from "mongodb";

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

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

interface Movie {
title: string;
}

async function run() {
try {
const database = client.db("sample_mflix");
const movies = database.collection<Movie>("movies");
const movies = database.collection("movies");

/* Delete all documents that match the specified regular
expression in the title field from the "movies" collection */
const result = await movies.deleteMany({ title: { $regex: "Santa" } });

// Print the number of deleted documents
console.log("Deleted " + result.deletedCount + " documents");
} finally {
// Close the client after the operation completes
await client.close();
}
}
// Run the program and print any thrown exceptions
run().catch(console.dir);