1

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?

1 Answer 1

3

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

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

Sign up to request clarification or add additional context in comments.

3 Comments

I've added documentation for this, thanks for bringing it to my attention: github.com/mongodb/mongo-python-driver/commit/…
@A.JesseJiryuDavis, and, also special thank you for all of your work on motor.
it's DEPRECATED now。

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.