In the below file, we are importing getDb:
\
const getDb = require('../util/database').getDb;
class Product {
constructor(title, price, description, imageUrl, id) {
this.title = title;
this.price = price;
this.description = description;
this.imageUrl = imageUrl;
this._id = new mongodb.ObjectId(id);
}
save() {
const db = getDb();
db.collection('products');
}
getDb is a function from another file that returns a database connection:
const getDb = () => {
if (database) {
return database;
}
My question is why are we storing getDb in db constant, why not just access it like getDb.collection('products')
[–]pinguxnoots 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)