Permalink
Browse files

add findAndModifyUpsert

  • Loading branch information...
1 parent e898d66 commit a57ad8ce6d399e48ee6d22d329c4068f24e105ff @lingzhe lingzhe committed Oct 7, 2012
Showing with 14 additions and 0 deletions.
  1. +14 −0 src/com/orange/common/mongodb/MongoDBClient.java
@@ -171,6 +171,20 @@ public DBObject findAndModify(String tableName, DBObject query,
false);
}
+ // returnNew = true, upsert = true
+ public DBObject findAndModifyUpsert(String tableName, DBObject query,
+ DBObject update) {
+ DBCollection collection = db.getCollection(tableName);
+ if (collection == null)
+ return null;
+
+ // System.out.println("update db, query = " + query.toString() +
+ // ", update = " + update.toString());
+ return collection.findAndModify(query, null, null, false, update, true,
+ true);
+ }
+
+
public void updateOne(String tableName, DBObject query, DBObject update) {
DBCollection collection = db.getCollection(tableName);
if (collection == null)

0 comments on commit a57ad8c

Please sign in to comment.