Skip to content

Commit 273c732

Browse files
norareidymongoKart
authored andcommitted
DOCSP-32718: insertOne comments (mongodb#758)
* DOCSP-32718: insertOne comments * addressing feedback
1 parent 69dbeb3 commit 273c732

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

source/code-snippets/usage-examples/insertOne.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ import { MongoClient } from "mongodb";
33
// Replace the uri string with your MongoDB deployment's connection string.
44
const uri = "<connection string uri>";
55

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

89
async function run() {
910
try {
11+
// Connect to the "insertDB" database and access its "haiku" collection
1012
const database = client.db("insertDB");
1113
const haiku = database.collection("haiku");
12-
// create a document to insert
14+
15+
// Create a document to insert
1316
const doc = {
1417
title: "Record of a Shriveled Datum",
1518
content: "No bytes, no problem. Just insert a document, in MongoDB",
1619
}
20+
// Insert the defined document into the "haiku" collection
1721
const result = await haiku.insertOne(doc);
1822

23+
// Print the ID of the inserted document
1924
console.log(`A document was inserted with the _id: ${result.insertedId}`);
2025
} finally {
26+
// Close the MongoDB client connection
2127
await client.close();
2228
}
2329
}
30+
// Run the function and handle any errors
2431
run().catch(console.dir);

0 commit comments

Comments
 (0)