import { MongoClient } from 'mongodb';
import assert from 'assert';
import config from './config';
console.log('Inside File');
MongoClient.connect(config.mongodbUri, (err, db) => {
assert.equal(null, err);
db.products.insertMany( [
{ item: "card", qty: 15 },
{ item: "envelope", qty: 20 },
{ item: "stamps" , qty: 30 }
] );
db.close();
});
For the above code i get the error Cannot read property insertMany of undefined. But when i just enter the below
db.products.insertMany( [
{ item: "card", qty: 15 },
{ item: "envelope", qty: 20 },
{ item: "stamps" , qty: 30 }
] );
in the console the products seems to get inserted in the db just fine. Can someone please let me know the cause of this issue?