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 – mongoc_database_get_collection_names_with_opts() — libmongoc 1.23.2 – 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 mongoc_client_command_with_opts() — libmongoc 1.23.2.

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