GetCollectionNames always returns null (c# driver v. 1.0.0.4098)

349 views
Skip to first unread message

Rob

unread,
Apr 13, 2011, 9:51:29 AM4/13/11
to mongodb-user
Hy everyone,

the method GetCollectionNames of the class MongoDatabase, always
returns [], although there are collections in the database.
Should it not return all the names of the collections in the database?
The javascript shell does give me back the collections, when I use the
same command.

thanks,

Rob Segerink

Robert Stam

unread,
Apr 13, 2011, 10:11:24 AM4/13/11
to mongodb-user
It's impossible for GetCollectionNames to return null, although it can
return an empty list if the database has no collections.

Also, GetCollectionNames filters out the names of any system
collections.

GetCollectionNames returns an empty list if the database doesn't
exist. Check the spelling of the database name in your call to
GetDatabase.

If you just type "db" in the mongo shell it will echo the name of the
current database. Verify that you are using the same database in the
shell and in the C# code.

Rob

unread,
Apr 13, 2011, 10:47:37 AM4/13/11
to mongodb-user
Hi Robert,

yes, sorry for that, my mistake, was not referencing to the same
database.... :(

thanks again for the quick reply.

Rob Segerink

Robert Stam

unread,
Apr 13, 2011, 10:50:35 AM4/13/11
to mongodb-user
You're welcome. Glad you were able to resolve it.

shweta maheshwari

unread,
May 17, 2016, 9:11:20 PM5/17/16
to mongodb-user
Hi,

I am using db.GetCollectionNames() in C# and I verified that I am referring to the correct database. I have 12 collections in my Database, still I a, getting empty list.
Could someone help?
Reply all
Reply to author
Forward
0 new messages