I am trying to find a way to list all of the validation rules of a mongodb collection and I would like to do it with python
In the mongo shell the command is this:
db.getCollectionInfos()
However I have not been able to identify an equivalent command in pymongo
db.foo.collection_infos()
db.foo.getCollectionInfos()
both fail with (or with something similar):
TypeError: 'Collection' object is not callable. If you meant to call the 'get_collection_infos' method on a 'Database' object it is failing because no such method exists.
Then I tried putting essentially random commands into the interpreter
db.command({"foo": "getCollectionInfos"})
Unsurprisingly that also didn't work.
The command wrapped by the getCollectionInfos
mongo shell command is listCollections
administrative command.
Administrative commands are available to run against the database. However, some mongo shell methods share similar names with administrative commands (.e.g. cloneConnection, currentOp, dropDatabase, and so on). It is easy to think that other mongo shell methods are administrative command but they aren't.
Using the listCollections command e.g.
# Return information for all collections in the database.
db.command('listCollections')
# Return information for collection `a`
db.command({'listCollections': 1, 'filter': {'name': 'a'}})