Warning on Connecting to MongoDB with a Node server

后端 未结 5 1450
有刺的猬
有刺的猬 2021-02-01 03:16

Connecting with MongoDB native driver

I wrote following code to connect mongodb through native driver which has been install with npm install mongodb --save

5条回答
  •  悲&欢浪女
    2021-02-01 03:35

    I got the same error and resolved using the below template.

    var MongoClient = require('mongodb').MongoClient
    
    const client = new MongoClient(uri, {useUnifiedTopology: true});
    
    client.connect().then((client)=>{
        var db = client.db('db_name')
        db.collection('collection_name').find().toArray(function (err, result) {
            if (err) throw err
            console.log(result);
        })
    })
    

    This worked for me. and now it's not showing any DepricationWarning.

提交回复
热议问题