-
Notifications
You must be signed in to change notification settings - Fork 52
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
/* 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 { | ||
// Access the movies collection from the sample_mflix database. | ||
const database = client.db("sample_mflix"); | ||
const movies = database.collection("movies"); | ||
// Query for all movies with a title containing the string "Santa" | ||
|
||
// Create a filter for movies with a title containing the string "Santa". | ||
const query = { title: { $regex: "Santa" } }; | ||
|
||
// Delete all documents that match the preceding query filter. | ||
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 handle any errors that occur during execution. | ||
run().catch(console.dir); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
/* 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); | ||
|
||
// Define the Movie interface to model the data. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: I'm open to any discussion, but I think some of the information is self-apparent. I think "Create a sample interface" contains enough information. Also, this code isn't used in this example, so I think it could be good to remove (feel free to ticket if it's not trivial to fix and check). |
||
interface Movie { | ||
title: string; | ||
} | ||
|
||
async function run() { | ||
try { | ||
// Access the movies collection from the sample_mflix database. | ||
const database = client.db("sample_mflix"); | ||
const movies = database.collection<Movie>("movies"); | ||
|
||
// Delete all documents where the title contains the string "Santa". | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: While I think it can be helpful to include values, since this is a regular expression, it might get awkward to try to reproduce this language for a more complex regular expression. I think it could be more general since the value is apparent and self-explanatory in the code. I think it could be helpful to skip the comment "Access the movies collection..." and reference the collection in this comment instead since this is closer to the usage of the collection. E.g. "Delete all documents that match the specified regular expression in the title field from the "movies" collection." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is also inconsistent with the other comment in the JS file even though the code is the same: |
||
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 handle any errors that occur during execution. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: "Run the program and print any thrown exceptions." |
||
run().catch(console.dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Lines 15-16 just get a reference to the collection. I think "access" means interact with it, which is started in line 22 when the deleteMany operation is called on the collection.