Are MongoDB bulk updates atomic if they apply to the same document?

416 views Asked by At

For the following command where query can only ever match one document (note that bulkWrite() is ordered by default):

final BulkWriteResult res = db.getCollection("mycol").bulkWrite(Arrays.asList(
    new UpdateOneModel<>(query,
        new Document("$addToSet", new Document("some_things", things))),
    new UpdateOneModel<>(query,
        new Document("$pull", new Document("some_things", otherthings)))));

... I understand that if the first update succeeds and the second fails (which under normal circumstances should be impossible) the first update will still be applied to the document, which means the bulk write isn't strictly atomic. However, assuming both queries succeed, is the operation atomic? E.g. can other writes interleave between the two operations or not?

0

There are 0 answers