Fetch name and type of collections in a db

Hi,
Is there a way to grab the name as well as the type of collections existing in a database using the mongo-c-driver? I see that we have a function – http://mongoc.org/libmongoc/current/mongoc_database_get_collection_names_with_opts.html#mongoc-database-get-collection-names-with-opts – that provides the collection names, wanted to see if there is a way through the mongo-c-driver to also grab the collection type, i.e. whether it is a view or just a collection.

Currently, the only way this seems possible is by sending a raw command to the server to list collections as obtained using http://mongoc.org/libmongoc/current/mongoc_client_command_with_opts.html#mongoc-client-command-with-opts.

Thanks,
Nachi

Hello @Nachi, mongoc_database_find_collection_with_opts may be what you want. That runs the listCollections command underneath, and returns documents describing the collection, which include a “type” field.

2 Likes