use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class QueryBatchCursor method asGetMoreCommandDocument.
private BsonDocument asGetMoreCommandDocument() {
BsonDocument document = new BsonDocument("getMore", new BsonInt64(serverCursor.getId())).append("collection", new BsonString(namespace.getCollectionName()));
int batchSizeForGetMoreCommand = Math.abs(getNumberToReturn(limit, this.batchSize, count));
if (batchSizeForGetMoreCommand != 0) {
document.append("batchSize", new BsonInt32(batchSizeForGetMoreCommand));
}
if (maxTimeMS != 0) {
document.append("maxTimeMS", new BsonInt64(maxTimeMS));
}
return document;
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class DropDatabaseOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument commandDocument = new BsonDocument("dropDatabase", new BsonInt32(1));
appendWriteConcernToCommand(writeConcern, commandDocument, description);
return commandDocument;
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class WriteProtocol method createGetLastErrorCommandDocument.
private BsonDocument createGetLastErrorCommandDocument() {
BsonDocument command = new BsonDocument("getlasterror", new BsonInt32(1));
command.putAll(writeConcern.asDocument());
return command;
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class WriteProtocol method getResponseDocument.
private BsonDocument getResponseDocument(final RequestMessage curMessage, final RequestMessage nextMessage, final WriteConcernResult writeConcernResult, final WriteConcernException writeConcernException) {
BsonDocument response = new BsonDocument("ok", new BsonInt32(1));
if (writeConcern.isAcknowledged()) {
if (writeConcernException == null) {
appendToWriteCommandResponseDocument(curMessage, nextMessage, writeConcernResult, response);
} else {
response.put("n", new BsonInt32(0));
BsonDocument writeErrorDocument = new BsonDocument("index", new BsonInt32(0)).append("code", new BsonInt32(writeConcernException.getErrorCode()));
if (writeConcernException.getErrorMessage() != null) {
writeErrorDocument.append("errmsg", new BsonString(writeConcernException.getErrorMessage()));
}
response.put("writeErrors", new BsonArray(singletonList(writeErrorDocument)));
}
}
return response;
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class DBObjectCodecTest method shouldEncodeIterableMapAsMap.
@Test
public void shouldEncodeIterableMapAsMap() {
IterableMap iterableMap = new IterableMap();
iterableMap.put("first", 1);
DBObjectCodec dbObjectCodec = new DBObjectCodec(fromProviders(asList(new ValueCodecProvider(), new DBObjectCodecProvider(), new BsonValueCodecProvider())));
DBObject doc = new BasicDBObject("map", iterableMap);
BsonDocumentWriter writer = new BsonDocumentWriter(new BsonDocument());
dbObjectCodec.encode(writer, doc, EncoderContext.builder().build());
assertEquals(new BsonDocument("map", new BsonDocument("first", new BsonInt32(1))), writer.getDocument());
}
Aggregations