dropDups=true; still get MongoException$DuplicateKey

371 views
Skip to first unread message

Joey Mink

unread,
Nov 1, 2011, 11:16:41 AM11/1/11
to mor...@googlegroups.com
Hi!

I'm using Morphia (morphia-1.00-20110403.170849-3.pom) and MongoDB v2.0.1.  I have an entity:

@Entity
@Indexes({
// Following index ensures no duplicate relationships:
@Index(value="integratedBy, stakeholderId, propertyId, type", unique=true, dropDups=true)
})
public class IntegratedRelationship extends IntegratedRecord {
@SuppressWarnings("unused")
@Id private ObjectId id;

private RelationshipType type;
private ObjectId stakeholderId;
private ObjectId propertyId;
private Float weight = 1.0f; // refs #586
private Class<? extends IAppIntegrator> integratedBy;
private Date creationDate;

However, I receive the following exception while adding IntegratedRelationship objects to the Datastore:

com.mongodb.MongoException$DuplicateKey: E11000 duplicate key error index: integration.IntegratedRelationship.$integratedBy_1_stakeholderId_1_propertyId_1_type_1  dup key: { : "com.exoanalytic.wm.warehouse.integration_layer.app.lodging.LodgingIntegrator", : ObjectId('4eb0098a948444f3a4e69920'), : ObjectId('4eb0098a948444f3a3e69920'), : "HOSPITALITY" }
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:135)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:157)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:141)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:241)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:197)
at com.mongodb.DBCollection.insert(DBCollection.java:59)
at com.mongodb.DBCollection.save(DBCollection.java:526)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:764)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:826)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:820)
at com.exoanalytic.wm.warehouse.integration_layer.app.lodging.LodgingIntegrator.integrateStrRecord(LodgingIntegrator.java:220)

Am I doing something wrong, by any chance?  My goal is to ensure uniqueness of my index, but silently drop duplicate records that result in the same index value.  Thanks in advance for any thoughts!

Joey

o-`o

Scott Hernandez

unread,
Nov 1, 2011, 11:40:49 AM11/1/11
to mor...@googlegroups.com
You will always get exceptions on unique index violations; that
options is just used when the index is first created, it has no effect
as documents are inserted/updated.

Joey Mink

unread,
Nov 1, 2011, 11:41:57 AM11/1/11
to mor...@googlegroups.com
Understood - thanks!

o-`o

Reply all
Reply to author
Forward
0 new messages