On mongodb manual there is an example for atomic operations on a single document.
book = {
_id: 123456789,
title: "MongoDB: The Definitive Guide",
available: 3,
checkout: [ { by: "joe", date: ISODate("2012-10-15") } ]
}
The manual states that the below operation is atomic:
db.books.findAndModify ( {
query: {
_id: 123456789,
available: { $gt: 0 }
},
update: {
$inc: { available: -1 },
$push: { checkout: { by: "abc", date: new Date() } }
}
} )
My question is what would happen if available field was an embedded document. Such as below:
book = {
_id: 123456789,
title: "MongoDB: The Definitive Guide",
available: [ { value: 3, valueFloat: 3.00 ] },
checkout: [ { by: "joe", date: ISODate("2012-10-15") } ]
}
Could I still do this operation atomically? If so, how?