Juan
Juan

Reputation: 422

How to obtain validator info with pymongo

In mongo shell I can retrieve the validator info of one collection with

db.getCollectionInfos({name: 'collection'})[0].options.validator

How is it done with pymongo?

Upvotes: 0

Views: 162

Answers (1)

Belly Buster
Belly Buster

Reputation: 8834

It's a bit obscure but it can be done:

import pymongo
db = pymongo.MongoClient()['mydatabase']

x = db.command({'listCollections': 1, 'filter': {'name': 'testcollection'}})
print(x.get('cursor').get('firstBatch')[0].get('options').get('validator'))

Upvotes: 1

Related Questions