Hey there, I’m running this example code from this docs page. When I run the code the single insertOne call is inserting two documents into the collection. I cannot figure out why this is happening. Here’s the code:
Const dbURI =
"mongodb+srv://user:password@cluster.xxxxx.mongodb.net/?w=majority";
const { MongoClient } = require("mongodb");
const client = new MongoClient(dbURI, { useUnifiedTopology: true });
async function run() {
try {
await client.connect();
const database = client.db("test");
const collection = database.collection("testcollection");
// create a document to be inserted
const doc = { name: "Red", town: "kanto" };
const result = await collection.insertOne(doc);
console.log(
`${result.insertedCount} documents were inserted with the _id: ${result.insertedId}`
);
} finally {
await client.close();
}
}
run().catch(console.dir);