firesofmay
firesofmay

Reputation: 602

MongoDB not showing collections information even though I am sure its there

So I am using MongoDB 3.2 version. I created a db and its collection via a Clojure wrapper called monger But when I connect to the mongo shell, and check if collections are created I can't see it.

Here's the code:

Primary> use db_name

PRIMARY> db.version()
3.2.3

PRIMARY> db.stats()
{
        "db" : "db_name",
        "collections" : 4,
        "objects" : 0,
        "avgObjSize" : 0,
        "dataSize" : 0,
        "storageSize" : 16384,
        "numExtents" : 0,
        "indexes" : 9,
        "indexSize" : 36864,
        "ok" : 1
}

PRIMARY> show collections

PRIMARY> db.coll1.getIndexes()
[ ]

PRIMARY> db.getCollectionInfos()
Tue May 24 16:29:44 TypeError: db.getCollectionInfos is not a function (shell):1

PRIMARY>

But when I check if collections are created via clojure I can see the information.

user=> (monger.db/get-collection-names mongo-db*)
#{"coll1" "coll2" "coll3" "coll4"}

What is going on?

Upvotes: 0

Views: 933

Answers (1)

firesofmay
firesofmay

Reputation: 602

Found the issue. So it turns out that if the mongo shell and running mongo instance are of two different versions then db.getCollectionNames() and db.collection.getIndexes() will return no output.

This can happen if you are connecting to a remote mongo instance and the instance via you are connecting to is running say 2.x shell version (you can see this when you start the shell) and the running mongo is 3.x version.

According to the documentation:

For MongoDB 3.0 deployments using the WiredTiger storage engine, if you run db.getCollectionNames() and db.collection.getIndexes() from a version of the mongo shell before 3.0 or a version of the driver prior to 3.0 compatible version, db.getCollectionNames() and db.collection.getIndexes() will return no data, even if there are existing collections and indexes. For more information, see WiredTiger and Driver Version Compatibility.

Spent almost an hour trying to figure this out, thought this might be helpful to others.

Upvotes: 2

Related Questions