I can't seem to find a getIndexes() command implemented as part of pymongo's Collection object - is that intentional? is it implemented somewhere else in the class hierarchy?
if it isn't, what's the pymongo canonical way for getting the same effect?
You can find all the available indexes in a MongoDB collection by using the getIndexes method. This will return all the indexes in a specific collection. Result: The output contains the default _id index and the user-created index student name index.
Create an index for a MongoDB collection, and specify the order. When you use PyMongo to create an index, you can pair the index name with either a 1 or a -1 integer value to explicitly set the sort order to ascending or descending, respectively.
What you might be looking for is index_information()
at the Collection level. From the docs:
Get information on this collection’s indexes.
Returns a dictionary where the keys are index names (as returned by create_index()) and the values are dictionaries containing information about each index.
>>> db.test.index_information() {u'_id_': {u'key': [(u'_id', 1)]}, u'x_1': {u'unique': True, u'key': [(u'x', 1)]}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With