Search code examples
mongodbmorphia

Is it possible to perform multiple DB operations on two sets of documents in single transaction in MongoDB using morphia


Can the following two update operations take place in one single transaction?

Query<Group> query1 = createQuery().disableValidation().field("users").equal(user.getUserId()).retrievedFields(true, "_id","users"); 
UpdateOperations<Group> ops1 = createUpdateOperations().removeAll("users", user);       
update(query1, ops1);

Query<Group> query = createQuery().field("_id").in(groupList);
UpdateOperations<Group> ops = createUpdateOperations().add("users", user);
update(query, ops);  

Solution

  • There are no multidocument transactions in mongodb. Writes to a single document are atomic, however. So no, there is no way to do that via morphia either.