Refine search
private static Bson compoundIndex(final List<String> fieldNames, final BsonValue value) { BsonDocument document = new BsonDocument(); for (String fieldName : fieldNames) { document.append(fieldName, value); } return document; } }
private static Bson orderBy(final List<String> fieldNames, final BsonValue value) { BsonDocument document = new BsonDocument(); for (String fieldName : fieldNames) { document.append(fieldName, value); } return document; }
private static Bson combine(final List<String> fieldNames, final BsonValue value) { BsonDocument document = new BsonDocument(); for (String fieldName : fieldNames) { document.remove(fieldName); document.append(fieldName, value); } return document; } }
static BsonDocument asExplainCommand(final BsonDocument command, final ExplainVerbosity explainVerbosity) { return new BsonDocument("explain", command) .append("verbosity", getVerbosityAsString(explainVerbosity)); }
@Override protected BsonDocument getAsWriteCommand(final ByteBufferBsonOutput bsonOutput, final int firstDocumentPosition) { List<ByteBufBsonDocument> documents = ByteBufBsonDocument.createList(bsonOutput, firstDocumentPosition); BsonDocument updateDocument = new BsonDocument("q", documents.get(0)).append("u", documents.get(1)); if (updateRequest.isMulti()) { updateDocument.append("multi", BsonBoolean.TRUE); } if (updateRequest.isUpsert()) { updateDocument.append("upsert", BsonBoolean.TRUE); } return getBaseCommandDocument("update").append("updates", new BsonArray(singletonList(updateDocument))); }
private BsonDocument createSaslContinueDocument(final BsonInt32 conversationId, final byte[] outToken) { return new BsonDocument("saslContinue", new BsonInt32(1)).append("conversationId", conversationId) .append("payload", new BsonBinary(outToken)); }
private BsonDocument getCommand() { BsonDocument command = new BsonDocument("listCollections", new BsonInt32(1)) .append("cursor", getCursorDocumentFromBatchSize(batchSize == 0 ? null : batchSize)); if (filter != null) { command.append("filter", filter); } if (nameOnly) { command.append("nameOnly", BsonBoolean.TRUE); } if (maxTimeMS > 0) { command.put("maxTimeMS", new BsonInt64(maxTimeMS)); } return command; }
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; }
private BsonDocument getCommandToEncode() { BsonDocument commandToEncode = command; if (!useOpMsg() && readPreference != null && !readPreference.equals(primary())) { commandToEncode = new BsonDocument("$query", command).append("$readPreference", readPreference.toDocument()); } return commandToEncode; }
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; }
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 BsonNull()) .append("n", new BsonDocument("$sum", new BsonInt32(1))))); return pipeline; }
private static BsonDocument addDriverInformation(final MongoDriverInformation mongoDriverInformation, final BsonDocument document) { MongoDriverInformation driverInformation = getDriverInformation(mongoDriverInformation); BsonDocument driverMetadataDocument = new BsonDocument(DRIVER_NAME_FIELD, listToBsonString(driverInformation.getDriverNames())) .append(DRIVER_VERSION_FIELD, listToBsonString(driverInformation.getDriverVersions())); document.append(DRIVER_FIELD, driverMetadataDocument); document.append(PLATFORM_FIELD, listToBsonString(driverInformation.getDriverPlatforms())); return document; }
private BsonDocument asGetMoreCommandDocument() { return new BsonDocument(COMMAND_NAME, new BsonInt64(cursorId)) .append("collection", new BsonString(namespace.getCollectionName())) .append("batchSize", new BsonInt32(numberToReturn)); }
private BsonDocument createSaslStartCommandDocument(final byte[] outToken) { return new BsonDocument("saslStart", new BsonInt32(1)).append("mechanism", new BsonString(getMechanismName())) .append("payload", new BsonBinary(outToken != null ? outToken : new byte[0])); }
@Override protected BsonDocument getAsWriteCommand(final ByteBufferBsonOutput bsonOutput, final int firstDocumentPosition) { BsonDocument deleteDocument = new BsonDocument("q", createOne(bsonOutput, firstDocumentPosition)) .append("limit", deleteRequest.isMulti() ? new BsonInt32(0) : new BsonInt32(1)); return getBaseCommandDocument("delete").append("deletes", new BsonArray(singletonList(deleteDocument))); }
@Override public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) { BsonDocument compoundIndex = new BsonDocument(); for (Bson index : indexes) { BsonDocument indexDocument = index.toBsonDocument(documentClass, codecRegistry); for (String key : indexDocument.keySet()) { compoundIndex.append(key, indexDocument.get(key)); } } return compoundIndex; } };
@Override public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) { BsonDocument combinedDocument = new BsonDocument(); for (Bson sort : sorts) { BsonDocument sortDocument = sort.toBsonDocument(documentClass, codecRegistry); for (String key : sortDocument.keySet()) { combinedDocument.append(key, sortDocument.get(key)); } } return combinedDocument; }
/** * Helper method for calling a 'dbStats' command. It returns storage statistics for a given database. * * @return result of the execution * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/dbStats/ Database Stats * @deprecated Prefer {@link #command(DBObject)} to run the dbStats command */ @Deprecated public CommandResult getStats() { BsonDocument commandDocument = new BsonDocument("dbStats", new BsonInt32(1)).append("scale", new BsonInt32(1)); return executeCommand(commandDocument); }
protected BsonDocument getBaseCommandDocument(final String commandName) { BsonDocument baseCommandDocument = new BsonDocument(commandName, new BsonString(getNamespace().getCollectionName())) .append("ordered", BsonBoolean.valueOf(isOrdered())); baseCommandDocument.append("writeConcern", WriteConcern.UNACKNOWLEDGED.asDocument()); return baseCommandDocument; }
@Override public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) { BsonDocument combinedDocument = new BsonDocument(); for (Bson sort : projections) { BsonDocument sortDocument = sort.toBsonDocument(documentClass, codecRegistry); for (String key : sortDocument.keySet()) { combinedDocument.remove(key); combinedDocument.append(key, sortDocument.get(key)); } } return combinedDocument; }