import com.mongodb.*; class Test { public static void main(String args[]) throws java.net.UnknownHostException { Mongo mongo = new Mongo(); DB db = mongo.getDB("testWriteConcern"); db.dropDatabase(); DBCollection coll = db.getCollection("foo"); assert(coll.count() == 0); WriteResult result = coll.insert(new BasicDBObject("foo", "bar")); assert(result.getError() == null); assert(coll.count() == 1); coll = db.getCollection("bar"); assert(coll.count() == 0); result = coll.insert(new BasicDBObject("foo", "bar"), WriteConcern.SAFE); assert(coll.count() == 1); assert coll.findOne(new BasicDBObject("foo", "bar")) != null; assert result.getLastError().get("wnote") == null : "WNote came through: " + result.getLastError().get("wnote"); } }