diff --git a/sense-support-mongodb/src/main/java/org/senseframework/support/orm/mongodb/Mongo.java b/sense-support-mongodb/src/main/java/org/senseframework/support/orm/mongodb/Mongo.java index dd75cbc1f51e9e5e22db79e5898d66af095583a0..8d910ca76f894454a6632bbfed409e8335c57858 100755 --- a/sense-support-mongodb/src/main/java/org/senseframework/support/orm/mongodb/Mongo.java +++ b/sense-support-mongodb/src/main/java/org/senseframework/support/orm/mongodb/Mongo.java @@ -1,6 +1,7 @@ package org.senseframework.support.orm.mongodb; -import com.mongodb.*; +import com.mongodb.WriteConcern; +import com.mongodb.WriteResult; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.senseframework.support.orm.mongodb.exception.QueryException; @@ -10,6 +11,7 @@ import org.springframework.data.domain.Sort; import org.springframework.data.geo.GeoResult; import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metrics; +import org.springframework.data.mongodb.core.FindAndModifyOptions; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.NearQuery; @@ -439,6 +441,14 @@ public class Mongo extends MongoQuery { return (T) mongoOperations.findAndModify(query, _update, clazz, collectionName(clazz)); } + public T findAndUpdate(Class clazz, IMongoUpdate update, boolean upsert, boolean returnNew) { + Update _update = new Update(); + update.update(_update); + init(); + FindAndModifyOptions options = new FindAndModifyOptions(); + options.upsert(upsert).returnNew(returnNew); + return (T) mongoOperations.findAndModify(query, _update, options, clazz, collectionName(clazz)); + } public T one(Class clazz) { init();