use of org.bson.BsonArray in project mongo-java-driver by mongodb.
the class WriteCommandResultHelper method getUpsertedItems.
@SuppressWarnings("unchecked")
private static List<BulkWriteUpsert> getUpsertedItems(final BsonDocument result) {
BsonValue upsertedValue = result.get("upserted");
if (upsertedValue == null) {
return Collections.emptyList();
} else {
List<BulkWriteUpsert> bulkWriteUpsertList = new ArrayList<BulkWriteUpsert>();
for (BsonValue upsertedItem : (BsonArray) upsertedValue) {
BsonDocument upsertedItemDocument = (BsonDocument) upsertedItem;
bulkWriteUpsertList.add(new BulkWriteUpsert(upsertedItemDocument.getNumber("index").intValue(), upsertedItemDocument.get("_id")));
}
return bulkWriteUpsertList;
}
}
use of org.bson.BsonArray 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.BsonArray in project mongo-java-driver by mongodb.
the class AggregateExplainOperation method getCommand.
private BsonDocument getCommand() {
BsonDocument commandDocument = new BsonDocument("aggregate", new BsonString(namespace.getCollectionName()));
commandDocument.put("pipeline", new BsonArray(pipeline));
commandDocument.put("explain", BsonBoolean.TRUE);
if (maxTimeMS > 0) {
commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS));
}
if (allowDiskUse != null) {
commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
}
if (collation != null) {
commandDocument.put("collation", collation.asDocument());
}
return commandDocument;
}
use of org.bson.BsonArray in project mongo-java-driver by mongodb.
the class AggregateToCollectionOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument commandDocument = new BsonDocument("aggregate", new BsonString(namespace.getCollectionName()));
commandDocument.put("pipeline", new BsonArray(pipeline));
if (maxTimeMS > 0) {
commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS));
}
if (allowDiskUse != null) {
commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
}
if (bypassDocumentValidation != null && serverIsAtLeastVersionThreeDotTwo(description)) {
commandDocument.put("bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation));
}
if (serverIsAtLeastVersionThreeDotSix(description)) {
commandDocument.put("cursor", new BsonDocument());
}
appendWriteConcernToCommand(writeConcern, commandDocument, description);
if (collation != null) {
commandDocument.put("collation", collation.asDocument());
}
return commandDocument;
}
use of org.bson.BsonArray in project mongo-java-driver by mongodb.
the class CreateIndexesOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument command = new BsonDocument("createIndexes", new BsonString(namespace.getCollectionName()));
List<BsonDocument> values = new ArrayList<BsonDocument>();
for (IndexRequest request : requests) {
values.add(getIndex(request));
}
command.put("indexes", new BsonArray(values));
appendWriteConcernToCommand(writeConcern, command, description);
return command;
}
Aggregations