@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)); } }
@Test public void testEnsureIndex() { MongoDataSource ds = getDataSource(); Mongo mongo = ds.getMongoInstance(); mongo.dropDatabase(DB); DBCollection coll = mongo.getDB(DB).getCollection(COLL); MongoUtils.ensureIndex(coll, "fieldName", false, false); MongoUtils.ensureIndex(coll, "fieldName", true, false); MongoUtils.ensureIndex(coll, "fieldName", true, true); MongoUtils.ensureIndex(coll, "fieldName", false, true); }