use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class CreateIndexesOperation method getIndex.
@SuppressWarnings("deprecation")
private BsonDocument getIndex(final IndexRequest request) {
BsonDocument index = new BsonDocument();
index.append("key", request.getKeys());
index.append("name", new BsonString(request.getName() != null ? request.getName() : generateIndexName(request.getKeys())));
if (request.isBackground()) {
index.append("background", BsonBoolean.TRUE);
}
if (request.isUnique()) {
index.append("unique", BsonBoolean.TRUE);
}
if (request.isSparse()) {
index.append("sparse", BsonBoolean.TRUE);
}
if (request.getExpireAfter(TimeUnit.SECONDS) != null) {
index.append("expireAfterSeconds", new BsonInt64(request.getExpireAfter(TimeUnit.SECONDS)));
}
if (request.getVersion() != null) {
index.append("v", new BsonInt32(request.getVersion()));
}
if (request.getWeights() != null) {
index.append("weights", request.getWeights());
}
if (request.getDefaultLanguage() != null) {
index.append("default_language", new BsonString(request.getDefaultLanguage()));
}
if (request.getLanguageOverride() != null) {
index.append("language_override", new BsonString(request.getLanguageOverride()));
}
if (request.getTextVersion() != null) {
index.append("textIndexVersion", new BsonInt32(request.getTextVersion()));
}
if (request.getSphereVersion() != null) {
index.append("2dsphereIndexVersion", new BsonInt32(request.getSphereVersion()));
}
if (request.getBits() != null) {
index.append("bits", new BsonInt32(request.getBits()));
}
if (request.getMin() != null) {
index.append("min", new BsonDouble(request.getMin()));
}
if (request.getMax() != null) {
index.append("max", new BsonDouble(request.getMax()));
}
if (request.getBucketSize() != null) {
index.append("bucketSize", new BsonDouble(request.getBucketSize()));
}
if (request.getDropDups()) {
index.append("dropDups", BsonBoolean.TRUE);
}
if (request.getStorageEngine() != null) {
index.append("storageEngine", request.getStorageEngine());
}
if (request.getPartialFilterExpression() != null) {
index.append("partialFilterExpression", request.getPartialFilterExpression());
}
if (request.getCollation() != null) {
index.append("collation", request.getCollation().asDocument());
}
if (request.getWildcardProjection() != null) {
index.append("wildcardProjection", request.getWildcardProjection());
}
if (request.isHidden()) {
index.append("hidden", BsonBoolean.TRUE);
}
return index;
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class ListCollectionsOperation method asQueryDocument.
private BsonDocument asQueryDocument(final ConnectionDescription connectionDescription, final ReadPreference readPreference) {
BsonDocument document = new BsonDocument();
BsonDocument transformedFilter = null;
if (filter != null) {
if (filter.containsKey("name")) {
if (!filter.isString("name")) {
throw new IllegalArgumentException("When filtering collections on MongoDB versions < 3.0 the name field " + "must be a string");
}
transformedFilter = new BsonDocument();
transformedFilter.putAll(filter);
transformedFilter.put("name", new BsonString(format("%s.%s", databaseName, filter.getString("name").getValue())));
} else {
transformedFilter = filter;
}
}
BsonDocument indexExcludingRegex = new BsonDocument("name", new BsonRegularExpression("^[^$]*$"));
BsonDocument query = transformedFilter == null ? indexExcludingRegex : new BsonDocument("$and", new BsonArray(asList(indexExcludingRegex, transformedFilter)));
document.put("$query", query);
if (connectionDescription.getServerType() == SHARD_ROUTER && !readPreference.equals(primary())) {
document.put("$readPreference", readPreference.toDocument());
}
if (maxTimeMS > 0) {
document.put("$maxTimeMS", new BsonInt64(maxTimeMS));
}
return document;
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class AggregateOperationImpl method getCommand.
BsonDocument getCommand(final SessionContext sessionContext, final int maxWireVersion) {
BsonDocument commandDocument = new BsonDocument("aggregate", aggregateTarget.create());
appendReadConcernToCommand(sessionContext, maxWireVersion, commandDocument);
commandDocument.put("pipeline", pipelineCreator.create());
if (maxTimeMS > 0) {
commandDocument.put("maxTimeMS", maxTimeMS > Integer.MAX_VALUE ? new BsonInt64(maxTimeMS) : new BsonInt32((int) maxTimeMS));
}
BsonDocument cursor = new BsonDocument();
if (batchSize != null) {
cursor.put("batchSize", new BsonInt32(batchSize));
}
commandDocument.put(CURSOR, cursor);
if (allowDiskUse != null) {
commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
}
if (collation != null) {
commandDocument.put("collation", collation.asDocument());
}
if (comment != null) {
commandDocument.put("comment", new BsonString(comment));
}
if (hint != null) {
commandDocument.put("hint", hint);
}
if (variables != null) {
commandDocument.put("let", variables);
}
return commandDocument;
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class CountDocumentsOperation method getPipeline.
private List<BsonDocument> getPipeline() {
ArrayList<BsonDocument> pipeline = new ArrayList<BsonDocument>();
pipeline.add(new BsonDocument("$match", filter != null ? filter : new BsonDocument()));
if (skip > 0) {
pipeline.add(new BsonDocument("$skip", new BsonInt64(skip)));
}
if (limit > 0) {
pipeline.add(new BsonDocument("$limit", new BsonInt64(limit)));
}
pipeline.add(new BsonDocument("$group", new BsonDocument("_id", new BsonInt32(1)).append("n", new BsonDocument("$sum", new BsonInt32(1)))));
return pipeline;
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class AsyncQueryBatchCursor method asGetMoreCommandDocument.
private BsonDocument asGetMoreCommandDocument(final long cursorId) {
BsonDocument document = new BsonDocument("getMore", new BsonInt64(cursorId)).append("collection", new BsonString(namespace.getCollectionName()));
int batchSizeForGetMoreCommand = Math.abs(getNumberToReturn(limit, this.batchSize, count.get()));
if (batchSizeForGetMoreCommand != 0) {
document.append("batchSize", new BsonInt32(batchSizeForGetMoreCommand));
}
if (maxTimeMS != 0) {
document.append("maxTimeMS", new BsonInt64(maxTimeMS));
}
return document;
}
Aggregations