alecxe
alecxe

Reputation: 473813

Creating a sparse index with pymongo

I need to create a sparse index from the python script using pymongo.

It seems like both collection.create_index and collection.ensure_index don't support sparse option.

According to the mongodb issue tracker perl and php drivers do support sparse option to ensure_index command already; looks like there is no plans to make it available in the python driver..

Are there any alternative ways to create a sparse index using pymongo?

Upvotes: 1

Views: 1340

Answers (1)

Zaid Masud
Zaid Masud

Reputation: 13443

I have to agree that the documentation isn't great here, but this works for me:

my_collection.ensure_index("mike", sparse = True)

Upvotes: 3

Related Questions