MongoDB - Error: invalid schema, expected mongodb

前端 未结 9 2052
悲&欢浪女
悲&欢浪女 2020-12-13 05:59

I\'m new in building application with MEAN Stack, I\'m trying to build a real time chat app, here is my server side :

console.log(\"Server running...!\");

v         


        
相关标签:
9条回答
  • 2020-12-13 06:57

    Try this, it works:

    mongoose.connect('mongodb://localhost:27017/shopping');
    
    0 讨论(0)
  • 2020-12-13 06:58

    Just figured out the same problem. Damned windows save quotes in environment.

    So if you use windows and wrote this way SET MONGO_URL="mongodb://localhost:27017/{name of your db}" It is not correct.

    Correct way is SET MONGO_URL=mongodb://localhost:27017/{name of your db} without quotes.

    Also i discovered that you must write protocol exactly - mongodb. There is code what check the protocol from file url_parser.js

    var result = parser.parse(url, true);
    
    if(result.protocol != 'mongodb:') {
        throw new Error('invalid schema, expected mongodb');
    }
    
    0 讨论(0)
  • 2020-12-13 07:06

    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

    0 讨论(0)
提交回复
热议问题