Is .collection()
cheap? Because in the example below, a
and b
are not the same...
import { MongoClient } from "mongodb";
const mongoClient = new MongoClient('mongodb://localhost:27017', { useUnifiedTopology: true });
mongoClient.connect().then(client => {
const a = client.db("test").collection("demo");
const b = client.db("test").collection("demo");
console.log(a == b); // false
mongoClient.close();
});
Should we use a single .collection()
instance all over the application?
Or is creating a .collection()
cheap?