node.js - Create atomic stored procedure / "stored JS" with MongoDB -


we need create atomic routine in our mongodb database.

we need iterate through collection, find highest number given field documents in collection, increment it. working legacy data need integrate, otherwise we'd have atomic sequence in place.

how can create stored js or stored procedure in mongodb can run whole routine atomically?

i seeing information nothing looking particularly clear me:

called stored javascript function mongoose?

https://groups.google.com/forum/#!topic/mongoose-orm/spn3wfdstx4

https://github.com/mongoosejs/mongoose-function

where can find information how write atomic/blocking stored procedure runs in mongodb, , how invoke stored procedure application?

(summarizing comments above)

at moment, there nothing in mongodb allow run piece of arbitrary logic (including, example, multiple queries gather data) atomically.

the best atomic thing mongodb has offer findandmodify. atomicity naturally restricted 1 document , have pretty limited list of update operators (that is, can't use fields of document, same regular updates).

it somewhat possible using application-level lock: application inserts or modifies special lock document, signal other parts of application "i'm using/updating this, please refrain touching it". after operation completed, application releases lock, it's free re-acquired else. of course, relies entirely on actors respecting lock agreements, not reliable, put mildly.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -