Skip to content

Commit

Permalink
add findAndModifyUpsert
Browse files Browse the repository at this point in the history
  • Loading branch information
lingzhe committed Oct 7, 2012
1 parent e898d66 commit a57ad8c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/com/orange/common/mongodb/MongoDBClient.java
Expand Up @@ -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)
Expand Down

0 comments on commit a57ad8c

Please sign in to comment.