[JAVA-546] ensureIndex not working with Java driver. Created: 27/Mar/12  Updated: 11/Sep/19  Resolved: 27/Mar/12

Status: Closed
Project: Java Driver
Component/s: Documentation
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: prudhvi chaganti Assignee: Unassigned
Resolution: Done Votes: 0
Labels: ensureIndex, java,
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7



 Description   

Hi, I am trying to use ensureIndex for my collection using Java Driver of MongoDB. I want to have an unique index to be placed on my collection. I have used usercollection.ensureIndex(new BasicDBObject("id", 1).append("unique", true));. Please help me with the correct code to be used.



 Comments   
Comment by Jeffrey Yemin [ 27/Mar/12 ]

Try

usercollection.ensureIndex(new BasicDBObject("id", 1), new BasicDBObject("unique", true));

or

usercollection.ensureIndex(new BasicDBObject("id", 1), null, true);

Generated at Thu Feb 08 08:52:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.