Search code examples
mongodbwindows-10centos6remote-connection

Mongodb not listing collections when connecting remotely from CentOS


Mongo server: Windows 10 (host) client: CentOS 6.2, a virtual box vm on windows 10 host. This is actually a cloudera quick start vm. Issue: mongodb connects to the remote server (from CentOS to Windows) via terminal, lists the databases fine, but 'show collections' just returns blank. That said, the collections are accessible because I can query any collection and the count also gives me the correct results. On the other hand, I have connected to the same mongo server from IntelliJ and it shows all the collections just fine.

Just curious as to why this is happening.. Any comments?

Side Note: is there a mongodb command to count the number of collections in a database?

Thanks

_Vamsi


Solution

  • Make sure you are using the database you want to show the collections for. You may be using a database that doesn't have any collections.

    > use desiredDatabase
    > show collections
    

    If the list is still empty, try signing in with an admin user account. The user needs to be able to perform the listCollections action. The dbAdmin role includes the listCollections action.

    To get the count you can use the getCollectionNames function which returns an array and you can get the length from that.

    > db.getCollectionNames().length