MongoDB - Error: invalid schema, expected mongodb

Try this, it works:

mongoose.connect('mongodb://localhost:27017/shopping');

This is because you are using the connection string in an improper format.

You are using localhost:27017/db/chat while it should be mongodb://localhost:27017/db/chat

The pattern for the connection string is mongodb://<HOSTNAME>:<PORT>/<DBNAME>

Article for reference: https://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html#mongoclient-connect


Sometimes, error might be with the quotes around environment variables. Remove them once and try. Might help.

Error might be with :

 set DATABASE_URI='mongodb://localhost:1000/my_app' && node index.js

Correct command will be:

  set DATABASE_URI=mongodb://localhost:1000/my_app && node index.js

I just had this issue as well and it was because I had the protocol wrong:

mongo://localhost:27017/test

The protocol being wrong can also cause this error. It should be like this:

mongodb://localhost:27017/test