@Test public void testWrapperUpdate() { MongoDataSource ds = getDataSource(); Mongo mongo = ds.getMongoInstance(); mongo.dropDatabase(DB); DBCollection coll = mongo.getDB(DB).getCollection(COLL); coll.setWriteConcern(WriteConcern.SAFE); BasicDBObject o1 = new BasicDBObject().append("name", "value"); coll.insert(o1); BasicDBObject o2 = new BasicDBObject().append("name", "newValue"); BasicDBObject update = new BasicDBObject().append("$set", o2); Assert.assertTrue(MongoUtils.wrapperUpdate(coll, o1, update)); Assert.assertEquals(1, coll.count(o2)); Assert.assertFalse(MongoUtils.wrapperUpdate(coll, o1, update)); }
public static boolean wrapperUpdate(DBCollection collection, DBObject query, DBObject update) { WriteResult wr = collection.update(query, update, false, true); Boolean updated = (Boolean)wr.getCachedLastError().get("updatedExisting"); if (updated == null || !updated) { return false; } return true; }
MongoUtils { public static boolean wrapperUpdate(DBCollection collection, DBObject query, DBObject update) { WriteResult wr = collection.update(query, update, false, true); Boolean updated = (Boolean)wr.getCachedLastError().get("updatedExisting"); if (updated == null || !updated) { return false; } return true; } }
MongoUtils { public static boolean wrapperUpdate(DBCollection collection, DBObject query, DBObject update) { WriteResult wr = collection.update(query, update, false, true); Boolean updated = (Boolean)wr.getCachedLastError().get("updatedExisting"); if (updated == null || !updated) { return false; } return true; }  }
MongoUtils { public static boolean wrapperUpdate(DBCollection collection, DBObject query, DBObject update) { WriteResult wr = collection.update(query, update, false, true); Boolean updated = (Boolean)wr.getCachedLastError().get("updatedExisting"); if (updated == null || !updated) { return false; } return true; }  static void ensureIndex(DBCollection collection, String fieldName, boolean unique, boolean sparse); static boolean wrapperUpdate(DBCollection collection, DBObject query, DBObject update); }
MongoUtils { public static boolean wrapperUpdate(DBCollection collection, DBObject query, DBObject update) { WriteResult wr = collection.update(query, update, false, true); Boolean updated = (Boolean)wr.getCachedLastError().get("updatedExisting"); if (updated == null || !updated) { return false; } return true; }  static void ensureIndex(DBCollection collection, String fieldName, boolean unique, boolean sparse); static boolean wrapperUpdate(DBCollection collection, DBObject query, DBObject update);  }