-
Notifications
You must be signed in to change notification settings - Fork 10
01_02 before end Latest MongoDb version getting error. #3
Description
I have to use the version used in the tutorial, but that is not ideal if I am in learning mongodb for now.
Any input helps.
DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
typeorm/mongo-typescript-example#1
`require('dotenv').config();
const users = require('./users');
const contacts = require('./contacts');
const MongoClient = require('mongodb').MongoClient;
const bcrypt = require('bcrypt');
function seedCollection(collectionName, initialRecords) {
MongoClient.connect(process.env.DB_CONN, (err, db) => {
console.log('connected to mongodb...');
const collection = db.collection(collectionName);
collection.remove();
initialRecords.forEach((item) => {
if (item.password) {
item.password = bcrypt.hashSync(item.password, 10);
}
});
collection.insertMany(initialRecords, (err, result) => {
console.log(`${result.insertedCount} records inserted.`);
console.log('closing connection...');
db.close();
console.log('done.');
});
});
}
seedCollection('users', users);
seedCollection('contacts', contacts);
`