### Question:
MongoUtils { public static void addFlag(int pmid, String flag, MongoConnection mongo) { BasicDBObject updateQuery = new BasicDBObject(ID, pmid + ""); BasicDBObject fList = new BasicDBObject(MongoFieldMapping.FILTER, new BasicDBObject(flag, 1)); mongo.coll.update(updateQuery, new BasicDBObject("$push", fList), true, false); }  static void addFlag(int pmid, String flag, MongoConnection mongo);  }### Answer:
@Test public void testAddFlag() throws Exception { String[] conn = MongoTest.getTestConn("MongoAddFlag"); MongoConnection mongo = new MongoConnection(conn); MongoUtils.addFlag(17, "blih", mongo); MongoUtils.addFlag(18, "blih", mongo); MongoUtils.addFlag(19, "blih", mongo); String query = "{ftr.blih:1}"; List<JCas> l = asList(createReader( MongoCollectionReader.class, BlueUima.PARAM_DB_CONNECTION, conn, BlueUima.PARAM_QUERY, query)); assertEquals("there should be 3 docs with flag 'blih'", 3, l.size()); MongoUtils.addFlag(17, "blah", mongo); MongoUtils.addFlag(28, "blah", mongo); query = "{ftr.blah:1}"; l = asList(createReader(MongoCollectionReader.class, BlueUima.PARAM_DB_CONNECTION, conn, BlueUima.PARAM_QUERY, query)); assertEquals("there should be 2 docs with flag 'blah'", 2, l.size()); }
@Test public void testQueryFlag() throws Exception { String[] conn = MongoTest.getTestConn("MongoAddFlag"); MongoConnection mongo = new MongoConnection(conn); MongoUtils.addFlag(17, "blih", mongo); MongoUtils.addFlag(18, "blih", mongo); MongoUtils.addFlag(19, "blih", mongo); MongoUtils.addFlag(20, "blih", mongo); MongoUtils.addFlag(21, "blih", mongo); MongoUtils.addFlag(22, "blih", mongo); String query = "{ftr.blih:1}"; List<JCas> l = asList(createReader( MongoCollectionReader.class, BlueUima.PARAM_DB_CONNECTION, conn, BlueUima.PARAM_QUERY, query)); assertEquals("there should be 2 docs with flag 'blah'", 6, l.size()); MongoUtils.addFlag(118, "asdfasdfblah", mongo); MongoUtils.addFlag(119, "blasfdasfdsfadh", mongo); MongoUtils.addFlag(17, "blah", mongo); MongoUtils.addFlag(18, "blah", mongo); MongoUtils.addFlag(18, "bluh", mongo); MongoUtils.addFlag(19, "bluh", mongo); MongoUtils.addFlag(20, "bluh", mongo); query = "{ $and: [ { ftr.blah: 1 }, { ftr.bluh: 1} ] }"; l = asList(createReader(MongoCollectionReader.class, BlueUima.PARAM_DB_CONNECTION, conn, BlueUima.PARAM_QUERY, query)); assertEquals("there should be 1 docs", 1, l.size()); query = "{ $and: [ { ftr.blah: { $ne: 1 } }, { ftr.bluh: 1} ] }"; l = asList(createReader(MongoCollectionReader.class, BlueUima.PARAM_DB_CONNECTION, conn, BlueUima.PARAM_QUERY, query)); assertEquals("there should be 2 docs", 2, l.size()); }