client.delete(new Delete("test", "insert", new BasicBSONObject("_id", 1)));
// insert new document
client.insert(
new Insert("test", "insert",
new BasicBSONObject("_id", 1)
.append("name", "test-name")
.append("integer", 100)
.append("long", 1000L)
.append("binary", "test binary".getBytes())
));
// find
Query query = new Query("test", "insert", 0, 1, new BasicBSONObject("_id", 1), null);
Response response = client.query(query);
Assert.assertNotNull(response);
Assert.assertEquals(1, response.getNumberReturned());
Assert.assertEquals(0, response.getStartingFrom());
Assert.assertEquals(query.getWaitingRequestId(), response.getHeader().getResponseTo());
BSONObject resultObject = response.getDocuments().get(0);
Assert.assertEquals(1, resultObject.get("_id"));
Assert.assertEquals("test-name", resultObject.get("name"));
Assert.assertEquals(100, resultObject.get("integer"));
Assert.assertEquals(1000L, resultObject.get("long"));
Assert.assertArrayEquals("test binary".getBytes(), (byte[]) resultObject.get("binary"));
// Duplicate error
MongoException me = null;
try {
client.insert(
new Insert("test", "insert",
new BasicBSONObject("_id", 1)
.append("name", "test-name2")
)
);
} catch (MongoException e) {