db.collectionNames doesn't work in Node.js

后端 未结 1 1658
花落未央
花落未央 2021-01-03 03:49

I want to check if a collection exist in Node.js. I use the db.collectionNames to get the names list in the db but nothing happened. The code:

connectDB(DBUR         


        
相关标签:
1条回答
  • 2021-01-03 04:06

    Are you using >2.0 version of the driver?

    If so, you will need to use listCollections instead - this is one of the changes in the update from 1.x

    Something like:

    db.listCollections().toArray(function(err, collections){
        //collections = [{"name": "coll1"}, {"name": "coll2"}]
    });
    
    0 讨论(0)
提交回复
热议问题