I want to add an index to my mongo collection outside of the interactive Mongo shell.
We're building in Python, so I could set it through MongoEngine, however, I'd greatly prefer to set the indexes directly.
Can I use db.eval() to make this happen?
I want to add an index to my mongo collection outside of the interactive Mongo shell.
We're building in Python, so I could set it through MongoEngine, however, I'd greatly prefer to set the indexes directly.
Can I use db.eval() to make this happen?
Copyright © 2021 Jogjafile Inc.
You can use
collection_name.create_indexAPI from Python.http://api.mongodb.org/python/1.11/api/pymongo/collection.html
If using Javascript, the problem with
eval()is that it needs a write lock, and creating an index itself needs a write lock. I do not think you can useeval()for anything that needs a write lock due to this reason.