const { MongoClient } = require("mongodb"); const uri = "mongodb://localhost:27017"; const client = new MongoClient(uri); async function run() { try { await client.connect(); const db = client.db("kamludb"); const users = db.collection("users"); // Adding a document await users.insertOne({ name: "Kamlendra", age: 39 }); // Reading documents const allUsers = await users.find().toArray(); console.log(allUsers); } finally { await client.close(); } } run().catch(console.dir);