27
votes

Any idea why i get this error?

this is the connect line

mongoose.connect("mongodb+srv://danielkmx:"+process.env.MONGO_ATLAS_PW+"@node-rest-shop-5xfup.mongodb.net/test",
{
    useMongoClient:true
});
6
you are concatenating wrong change "mongodb+srv://" to "mongodb://"+srv+"://"danilo
npmjs.com/package/npm-check-updates I got the same error.and solved with this link.You need to update your package.Khyati Bhojawala

6 Answers

33
votes

I had the same error, and it got resolved when I updated the mongoose package to the latest version.

11
votes

I think by now you have found an answer to this problem but I will explain, in the case that anyone else has the same problem

So generally we have 2 protocols(1- mongodb+srv:// & 2- mongodb://) right now to connect to a mongodb database.

the main difference between these 2 is the mongodb and its core version which you can find in the package-lock.json file, something like the code below:

"mongodb": {
  "version": "3.0.0", //Your MongoDB version
  "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.0.0.tgz",
  "integrity": "",
  "requires": {
    "mongodb-core": "3.0.0"
  }
},
"mongodb-core": {
  "version": "3.0.0", //Your MongoDB version
  "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.0.0.tgz",
  "integrity": "",
  "requires": {
    "bson": "1.0.9",
    "require_optional": "1.0.1"
  }
},

This if you wanna use the mongodb+srv:// version then you need a driver of version 3.0.0 or higher which you can simply do by:

npm install mongodb@3.0.0

**Or higher

I hope you find this helpful and if this solution is working for you please confirm it that other users do not face our issue again

3
votes

I agree with the solution and voted up for the question and very correct answers here.

In case someone wants to update the latest package(s), I suggest npm-check-updates (https://www.npmjs.com/package/npm-check-updates) for smooth updating.

Install npm-check-updates:

    $ sudo npm install -g npm-check-updates

Check latest updates of the used packages:

    $ ncu

Update packages:

    $ ncu -u

Then, install the updated packages:

    $ npm install
1
votes

Using the following version of the mongoose helped me solve this problem

npm i mongoose@5.7.0
0
votes

I faced the same problem but with mongorestore command. I did brew update mongodb which resulted in the following error.

unknown or unsupported macOS version: :mountain_lion

I then uninstalled mongodb and installed database tools by running brew install mongodb/brew/mongodb-database-tools which solved the problem for me and I was able to restore the database using following command:

mongorestore --uri=mongodb+srv://<user>:<password>@cluster0.wtdv4.mongodb.net/<db-name> --db <db-name> <input-dir>

0
votes

Although i had required versions of MongoDB, and mongoose, as i was making socket package for the application, my socket package was not up to date due to which it did not work, so crux is to ensure packages are updated to fit in new changes.