TypeError: db.collection is not a function

后端 未结 18 2471
青春惊慌失措
青春惊慌失措 2020-11-27 03:09

I am trying to post data to database that I have created on mLab and I am getting this error but I don\'t know whats going wrong.I also have read previously asked question o

18条回答
  •  温柔的废话
    2020-11-27 03:36

    According to the mongo document, we need to change the connection as bellow,

    The legacy operation
    MongoClient.connect('mongodb://localhost:27017/test', (err, db) => {
        // Database returned
    });
    
    is replaced with
    MongoClient.connect('mongodb://localhost:27017/test', (err, client) => {
        // Client returned
        var db = client.db('test');
    });
    

    Don't need to downgrade the mongo version :)

提交回复
热议问题