Referencing the guide here, http://docs.mongodb.org/manual/core/indexes/ I cannot tell if Mongo indexes for fields are stored persistently.
If ensureIndex() is called (and completes) within an application using MongoDB, what happens if:
- The application using
MongoDBis restarted. Will a subsequent call toensureIndex()cause a complete reindex? - The
MongoDBserver is restarted. Would a later call ofensureIndex()from a client application rebuild? - Is any of this affected by having multiple client sessions? I assume indexing is global across the entire collection per the documentation:
"MongoDB defines indexes on a per-collection level."
No, it should (as in every other driver) register as a no op since the index already exists. Some drivers provide a cache mechanism to detect, without going to the server, if an index has been created (i.e. Python).
Same as above
Yes indexes are stored in MongoDB on the collection itself (to be technical, as a namespace within the
db.nsfile). Since it is a single point of knowledge forensureIndexand an index is a single process (much like the write lock really) multiple connections should not effect whether the index creation is registered twice.