Dealing with concurrent requests in Meteor -


I am dealing with a problem where a user can update a document within a specified time frame, and If it does not, the server will be.

This update involves increasing a value and adding a document to an array for an object. I need to make sure that the user / server updates only one of the documents. To not do this, to ensure that some documents have already been updated, but there are some time where users and servers run at the same time and both check and pass, the document will be updated twice is.

I am trying many different ways to fix it, but I have not been able to. I tried to apply a lock like this: to ensure that only one update will occur and the second update will fail, but I have not succeeded. Any ideas?

To ensure this, some checks can be seen whether the document is already It has been updated, but there are times where users and servers run right at the same time and pass both checks and then the document is updated twice.

You can find it MongoDB update query which checks that the value has been updated and updated. Like it:

  var post = post.fundon ("id"); // ... some stuff with the post ... post.update ({counter: postcountry}, {$ push: {items: newItem}, $ inc: {counter: 1}});  

As you can see, in a query, we check both the counter and increase it - so if two of these questions run right after one, then in fact The document will be updated (the counter will no longer match)


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -