Is there a difference between createIndex and ensureIndex?
I note that in the shell documentation createIndex is deprecated and in the C# and Java drivers ensureIndex is deprecated.
Is there a difference between createIndex and ensureIndex?
I believe the original intent of the methods was that "createIndex" returns a status if the index already exists, while "ensureIndex" does not. There is no "ensureIndex" command on the server side, so the mongo shell and drivers are actually providing the "ensure" logic.
I note that in the shell documentation createIndex is deprecated and in the C# and Java drivers ensureIndex is deprecated.
This is indeed confusing -- I've raised issues to make the shell documentation consistent with the drivers: DOCS-4539, DOCS-4540.
FYI, some of the drivers had ensureIndex logic to cache whether an index had already been created (in an attempt to save round trips to the server) but the implementations of createIndex & ensureIndex were otherwise identical. The convention of "createIndex" was chosen to align with the server command "createIndexes" which was added in MongoDB 2.6. For some background you can see discussion on: https://jira.mongodb.org/ browse/JAVA-1097.
댓글 없음:
댓글 쓰기