Parallel insert into MongoDB -


what happens, if 2 clients, working 1 mongodb instance, perform , insert operation @ same time without «forceserverobjectid: true». possible generated equal objectids, there may conflict?

there implied unique index on _id field of every collection makes impossible 2 objects same _id exist in same collection.

when 2 objects same _id value stored collection.save, 1 document replace other.

when stored collection.insert, 1 of inserts fail duplicate key error.

but note mongodb objectids include 24bit machine-id. makes impossible 2 clients generate same id, unless have same machine-id. , it's unlikely. that, of course, applies when let mongodb driver (or shell) auto-generate objectids. mongodb allows use value of type value _id field when set manually. when (you shouldn't), it's responsibility ensure uniqueness.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -