Atomicity of findAndModify on embedded documents
问题 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