Home > OS >  db.listCollections() does not work in mongodb6.0.3
db.listCollections() does not work in mongodb6.0.3

Time:12-29

I used mongodb version < 4. Now I needed to install mongodb on ubuntu 22, the easiest way was to install version 6.0.3 But now some of the functionality does not work, for example

db.listCollections() 

-There were no problems, but after upgrading to mongodb6.0.3 - it does not work. I read that it is advised to use

db.getCollectionNames()

Are these functions interchangeable? Is there no difference between them? And is it possible to make db.listCollections() work in version 6.0.3?

I read here that many functions are already outdated in version 5

CodePudding user response:

db.listCollections() was a convenience wrapper in the legacy shell.

To get the same behavior in mongosh, use the listCollections database command, like

db.runCommand("listCollections")

  • Related