[DOCS-694] problem about creating unqiue index with "dropDups" option Created: 30/Oct/12 Updated: 03/Nov/17 Resolved: 06/Nov/12 |
|
| Status: | Closed |
| Project: | Documentation |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | auto | Assignee: | Sam Kleinman (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | collector-298ba4e7 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Mongodb: 2.2.0 Location: http://cn.docs.mongodb.org/manual/ |
||
| Participants: | |
| Days since reply: | 11 years, 15 weeks, 1 day ago |
| Description |
|
db.people.insert([ { "_id" : ObjectId("508f639c086512dc1f8694bd"), "username" : "smith", "age" : 48, "user_id" : 0 }, { "_id" : ObjectId("508f63a1086512dc1f8694be"), "username" : "smith", "age" : 30, "user_id" : 1 }, { "_id" : ObjectId("508f63ae086512dc1f8694bf"), "username" : "john", "age" : 36, "user_id" : 2 }, { "_id" : ObjectId("508f63b9086512dc1f8694c0"), "username" : "john", "age" : 18, "user_id" : 3 }, { "_id" : ObjectId("508f63ca086512dc1f8694c1"), "username" : "joe", "age" : 36, "user_id" : 4 }, { "_id" : ObjectId("508f63d5086512dc1f8694c2"), "username" : "john", "age" : 7, "user_id" : 5 }, { "_id" : ObjectId("508f63e0086512dc1f8694c3"), "username" : "simon", "age" : 3, "user_id" : 6 }, { "_id" : ObjectId("508f63ee086512dc1f8694c4"), "username" : "joe", "age" : 27, "user_id" : 7 }, { "_id" : ObjectId("508f63f9086512dc1f8694c5"), "username" : "jacob", "age" : 17, "user_id" : 8 }, { "_id" : ObjectId("508f6404086512dc1f8694c6"), "username" : "sally", "age" : 52, "user_id" : 9 }, { "_id" : ObjectId("508f640d086512dc1f8694c7"), "username" : "simon", "age" : 59, "user_id" : 10 }]) db.people.ensureIndex( {"age": 1}, {"dropDups": true}) # step 1 , {"unique": true, "dropDups": true}) # step 2 The step 2 doesn't take effect after I run step 1... Reporter: Ryououki |
| Comments |
| Comment by auto [ 06/Nov/12 ] |
|
Author: {u'date': u'2012-11-06T18:24:13Z', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}Message: |
| Comment by Sam Kleinman (Inactive) [ 30/Oct/12 ] |
|
That's correct. The ensureIndex will not rebuild an index if that index already exists with that field. In this situation, you would need to drop the index and recreate it with the desired options. On a related note, as a general rule, it's a good idea to not call the ensureIndex option as part of application startup in production systems: at best it's a no-op, and at worst a typo or change in configuration can render a production system inaccessible while it builds an unnecessary index. I'll make a change to the docs soon that will underscore both of these aspects of the ensureIndex command. |