Skip to content

DOCSP-32718: deleteone UE code comments #756

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 3 commits into from
Aug 31, 2023
Merged
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: 10 additions & 3 deletions source/code-snippets/usage-examples/deleteOne.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Delete a document

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>";

const client = new MongoClient(uri);
Expand All @@ -10,17 +12,22 @@ async function run() {
const database = client.db("sample_mflix");
const movies = database.collection("movies");

// Query for a movie that has title "Annie Hall"
/* Delete the first document in the "movies" collection that matches
the specified query document */
const query = { title: "Annie Hall" };

const result = await movies.deleteOne(query);

/* Print a message that indicates whether the operation deleted a
document */
if (result.deletedCount === 1) {
console.log("Successfully deleted one document.");
} else {
console.log("No documents matched the query. Deleted 0 documents.");
}
} finally {
// Close the connection after the operation completes
await client.close();
}
}
// Run the program and print any thrown exceptions
run().catch(console.dir);