Melvin
unread,Jul 7, 2010, 10:16:33 AM7/7/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
There is an unique index on two fields to prevent duplicates:
BSONObjBuilder index;
index.append( "name", 1 );
index.append( "value", 1 );
mDBConn.ensureIndex( "my.objects", index.obj( ), true );
However, the code in the following snippet, doesn't throw an exception
when I try to insert a duplicate:
try
{
// Insert into DB
BSONObjBuilder builder;
data->serialize( builder );
mDBConn.insert( "my.objects", builder.obj() );
}
catch ( DBException &e )
{
cout << "Error inserting: " << e.getCode() << " " << e.what();
}
The duplicate isn't saved into the database, so that's expected
behavior. What I also would expect, is an exception being thrown in C+
+, but that doesn't happen.
In the output of mongod I notice the error/exception is detected:
Caught Assertion in insert , continuing
insert my.objects exception userassert:E11000 duplicate key error
index: my.objects.$name_1_value_1 dup key { : "Foo", : "Bar" }
Is the issue, described above, a bug perhaps? Or am I doing something
wrong?