ojon
ojon

Reputation: 353

pull push atomic operation?

I have a document with 2 arrays, I want to move one element from one array to the other, I tried this on the console and it works:

db.examplecol.update({_id: ObjectId("5056b4b2b9f53a21385076c5")} , {'$pull':{setA:3}, '$push':   {setB:3}})

But I haven't seen yet an example of 2 updates in a single command. My question is if this is an atomic operation? If something goes wrong in the middle of this operation, do I have the risk of "losing" my element by it have been pulled but not pushed?

Upvotes: 3

Views: 3007

Answers (1)

slee
slee

Reputation: 534

Based on MongoDB's Atomic Operations documentation and since your operation is on a single document, then the operation should be atomic. You should ensure that you're using journalling, so if the power is pulled half-way through your update, then MongoDB will recover to a known, good state prior to the update.

Upvotes: 7

Related Questions