6566676869707172
ObjectId id = new ObjectId("47cc67093475061e3d95369d"); WriteResult writeResult = collection.remove(id); /* then */ assertThat(writeResult).isNotNull(); Friend friend = collection.findOne().as(Friend.class); assertThat(friend).isNull(); }
7980818283848586
/* when */ WriteResult writeResult = collection.remove("{name:#}", "John"); /* then */ assertThat(writeResult).isNotNull(); Friend friend = collection.findOne().as(Friend.class); assertThat(friend).isNull(); }
949596979899100101
/* when */ WriteResult writeResult = collection.remove(); /* then */ assertThat(writeResult).isNotNull(); Friend friend = collection.findOne().as(Friend.class); assertThat(friend).isNull(); }
101102103104105106107108109110111
} @Test public void whenNoSpecifyShouldSaveWithCollectionWriteConcern() throws Exception { Friend john = new Friend("John"); collection.save(john); WriteResult writeResult = collection.save(john); assertThat(writeResult.getLastConcern()).isEqualTo(collection.getDBCollection().getWriteConcern());
112113114115116117118119120121122
} @Test public void canRemoveWithWriteConcern() throws Exception { Friend john = new Friend("John"); collection.save(john); WriteResult writeResult = collection.withWriteConcern(WriteConcern.SAFE).remove(); assertThat(writeResult.getLastConcern()).isEqualTo(WriteConcern.SAFE);
27282930313233
import java.net.UnknownHostException; class BenchUtil { public static Friend createFriend(int id) { return new Friend("John" + id, "Address" + id, new Coordinate(1, id)); }