Skip to content

01_02 before end Latest MongoDb version getting error. #3

Description

@rogerprz

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

https://www.google.com/search?ei=3RfiW-edFKvjjwSGm7aABg&q=mongodb+To+use+the+new+parser%2C+pass+option+%7B+useNewUrlParser%3A+true+%7D+to+MongoClient.connect.&oq=mongodb+To+use+the+new+parser%2C+pass+option+%7B+useNewUrlParser%3A+true+%7D+to+MongoClient.connect.&gs_l=psy-ab.3...1638.3410..3738...1.0..0.158.1242.0j9......0....1..gws-wiz.......0i7i30.RVO3V27zwsE

`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);
`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions