On Oct 7, 2011 1:15 PM, "John Matthews" <jwmat...@gmail.com> wrote:
>
> Will mongodb handle an insert on a collection as an atomic operation
> from the perspective of the insert completing and the unique indexes
> being updated?
Yes, the document is inserted and the indexes are updated at the same time.
> The behavior I am seeing looks like this is not true (Assume 2 threads
> both inserting identical parameters).
> 1) Thread-A inserts a new document into mongodb
> 2) guess: mongodb updates unique indexes on collection
> 3) Thread-B attempts to insert an identical document and gets a
> DuplicateKeyError
> 4) Thread-B then attempts a find() on same parameters and sees no
> matches
> 5) guess: mongodb completes insert of document from step #1
> 6) Now Thread-B could continue with a find() using the same
> parameters and it will work
>
>
> Our problem:
> A DuplicateKeyError exception is raised from pymongo when inserting a
> new document,
> the exception is caught and we attempt to execute a find() on the same
> parameters, expecting a match, yet no match is returned.
Do you have more than one unique index on that collection? If, could you be crecking the wrong one?
You need to search on just the values in the unique index being violated. Not the other parts of the doc.
> We have several threads looping over a collection of rpms, storing
> information about the rpm in mongo.
> We have a unique index on (name, version, epoch, release, arch), these
> are fields of each document we create to represent the rpm.
>
> Versions we are using
> # rpm -qa | grep mongo
> mongodb-1.6.4-3.el6_0.x86_64
> mongodb-server-1.6.4-3.el6_0.x86_64
> pymongo-1.9-8.el6_1.x86_64
> pymongo-debuginfo-1.9-8.el6_1.x86_64
>
> More details about our issue can be found here:
> https://bugzilla.redhat.com/show_bug.cgi?id=734782
>
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
Are these fields very large? There is a limit to the maximum a index
entry can be; ~800-1K bytes
If you are able to reproduce this please file an issue on jira with
that reproduction case.