[SERVER-21888] Provide operation to determine if an index exists Created: 13/Dec/15 Updated: 14/Apr/16 Resolved: 14/Mar/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Eric Stobbart | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Sprint: | Query 11 (03/14/16) | ||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
|
I'm currently using the python driver. I'd like to be able to ask the server if my indexes exist per collection. Or have `getIndexes` return a stable document that I can compare against. Discussion started @github with the following pull request.. https://github.com/mongodb/mongo-python-driver/pull/299 |
| Comments |
| Comment by Max Hirschhorn [ 14/Mar/16 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Closing as a duplicate of SERVER-18518. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Max Hirschhorn [ 05/Mar/16 ] | ||||||||||||||||||||||||||||||||||||||||||||||
Sure you can. It just has to be on a database and collection with the same name as what is specified in the "ns" field.
This has already been requested in SERVER-18518, so if that's the functionality you're really looking for, then I'm inclined to close this ticket as a duplicate. My thoughts on some of the discussion in the pull requestDetermining whether two createIndexes requests are the same seems like a different question than whether those two requests will create the same indexes. The definition of whether index A is equivalent to index B seems dependent on the use-case. For instance,
seems problematic to me where an application wants to ensure that their usages of db.mycoll.find({}).hint(<index_name>) are valid. I'd be concerned about a driver attempting to define what it means for one index to be equivalent to another.
The results of the "listIndexes" command are stable in the sense that there won't be breaking changes to the contents of the "infoObj" because indexes created on older versions of MongoDB should be usable on newer versions of MongoDB. When new index options are added (e.g. storageEngine in 3.0 and partialFilterExpression in 3.2), then these options will become additional properties that the "listIndexes" command returns as part of the information regarding the index. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Eric Stobbart [ 14/Dec/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks guys. Just for some context on what I'm during currently, I only check the keys and direction. I'm not concerned with the name generated or if it was created in the background. I'm just making sure that the indexes exist on any database I'm working with. Also an issue I ran into was that the read's were allowed on secondaries, even though the primary hadn't completed the index and replicated yet. My index manager now goes through all the nodes, gets an index list per collection and compares. If an index was missing I'd also check the currentOp to see if it was being created and it's progress. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Bernie Hackett [ 14/Dec/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
No worries, I think your idea is correct. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sam Kleinman (Inactive) [ 14/Dec/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
behackett sorry for the confusion. I'm going to retitle this issue to "provide operation to determine if index exists", and make this a feature request. Please let me know if I'm mischaracterizing the issue here. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Bernie Hackett [ 14/Dec/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
One solution to this ticket might be to add the ability to query for an index document (by name, key, etc.). That used to be possible when indexes where defined in system.indexes, but no longer with the listIndexes command. A query option for listIndexes might do the trick. |