Concurrency issues and how to resolve them.
Currently ,we are facing lot of issues in stage environment , where in because of both node asynchrosity and mongo concurrency ,
We are seeing the parallel calls being made , and because of which we could see our quantities being mismatched ,
we dont have a unique key to put forth , but even we tried putting unique index, even then , we are run a data load of 100k + ,for few of the records , we could see duplicates being inserted !!
Please let us know how to resolve them .
Should we implement any locking mechanism :
Locking mechanism in mongodb (exclusive Lock , Collection lock and document lock)
Please suggest some mechanisms to resolve
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/79c031df-e5c3-4b83-b375-23c7e8be1de4%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/184379c1-8054-4738-b3ea-e1a1ad7a22e0%40googlegroups.com.
Hi,
Just to add to the discussion, you may want to check out the db.collection.update() with upsert to see if it can be used to solve your problem. If the document doesn’t yet exist on the database, upsert will insert a single document instead. For example:
db.test.update({_id:123}, {$set:{field1:true}}, {upsert:true})
The update statement will attempt to update a document with _id: 123
. If the document doesn’t exist, it will create one instead. Regardless of the path taken, the resulting collection will contain:
> db.test.find()
{
"_id": 123,
"field1": true
}
Also, there is an excellent blog post by A. Jesse Jiryu Davis that gives a detailed explanation into a similar issue: How to write resilient MongoDB applications
Best regards,
Kevin