/** * Creates a filter that matches all documents that either contain or do not contain the given field, depending on the value of the * exists parameter. * * @param fieldName the field name * @param exists true to check for existence, false to check for absence * @return the filter * @mongodb.driver.manual reference/operator/query/exists $exists */ public static Bson exists(final String fieldName, final boolean exists) { return new OperatorFilter<BsonBoolean>("$exists", fieldName, BsonBoolean.valueOf(exists)); }
private void addJ(final BsonDocument document) { if (journal != null) { document.put("j", BsonBoolean.valueOf(journal)); } }
private void addFSync(final BsonDocument document) { if (fsync != null) { document.put("fsync", BsonBoolean.valueOf(fsync)); } }
@Override public BsonBoolean decode(final BsonReader reader, final DecoderContext decoderContext) { boolean value = reader.readBoolean(); return BsonBoolean.valueOf(value); }
@Override public void doWriteBoolean(final boolean value) { write(BsonBoolean.valueOf(value)); }
command.append("tailable", BsonBoolean.valueOf(tailableCursor)); command.append("noCursorTimeout", BsonBoolean.valueOf(noCursorTimeout)); command.append("oplogReplay", BsonBoolean.valueOf(oplogReplay)); command.append("awaitData", BsonBoolean.valueOf(awaitData)); command.append("allowPartialResults", BsonBoolean.valueOf(partial));
@Override public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) { BsonDocument searchDocument = new BsonDocument("$search", new BsonString(search)); String language = textSearchOptions.getLanguage(); if (language != null) { searchDocument.put("$language", new BsonString(language)); } Boolean caseSensitive = textSearchOptions.getCaseSensitive(); if (caseSensitive != null) { searchDocument.put("$caseSensitive", BsonBoolean.valueOf(caseSensitive)); } Boolean diacriticSensitive = textSearchOptions.getDiacriticSensitive(); if (diacriticSensitive != null) { searchDocument.put("$diacriticSensitive", BsonBoolean.valueOf(diacriticSensitive)); } return new BsonDocument("$text", searchDocument); }
static BsonDocument asCommandDocument(final MongoCredential credential, final ConnectionDescription connectionDescription, final boolean readOnly, final String commandName) { boolean serverDigestPassword = serverIsAtLeastVersionFourDotZero(connectionDescription); BsonDocument document = new BsonDocument(); document.put(commandName, new BsonString(getUserNameNonNull(credential))); if (serverDigestPassword) { document.put("pwd", new BsonString(new String(getPasswordNonNull(credential)))); } else { document.put("pwd", new BsonString(createAuthenticationHash(getUserNameNonNull(credential), getPasswordNonNull(credential)))); } document.put("digestPassword", BsonBoolean.valueOf(serverDigestPassword)); document.put("roles", new BsonArray(Collections.<BsonValue>singletonList(new BsonString(getRoleName(credential, readOnly))))); return document; }
private BsonDocument getCommand(final ConnectionDescription description) { BsonDocument commandDocument = new BsonDocument("renameCollection", new BsonString(originalNamespace.getFullName())) .append("to", new BsonString(newNamespace.getFullName())) .append("dropTarget", BsonBoolean.valueOf(dropTarget)); appendWriteConcernToCommand(writeConcern, commandDocument, description); return 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; }
/** * Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a {@code '$'} sign. * * @param fieldName the field name, prefixed by a {@code '$' sign} * @param unwindOptions options for the unwind pipeline stage * @return the $unwind pipeline stage * @mongodb.driver.manual reference/operator/aggregation/unwind/ $unwind * @mongodb.server.release 3.2 * @since 3.2 */ public static Bson unwind(final String fieldName, final UnwindOptions unwindOptions) { notNull("unwindOptions", unwindOptions); BsonDocument options = new BsonDocument("path", new BsonString(fieldName)); Boolean preserveNullAndEmptyArrays = unwindOptions.isPreserveNullAndEmptyArrays(); if (preserveNullAndEmptyArrays != null) { options.append("preserveNullAndEmptyArrays", BsonBoolean.valueOf(preserveNullAndEmptyArrays)); } String includeArrayIndex = unwindOptions.getIncludeArrayIndex(); if (includeArrayIndex != null) { options.append("includeArrayIndex", new BsonString(includeArrayIndex)); } return new BsonDocument("$unwind", options); }
private BsonDocument getCommand(final ConnectionDescription description) { BsonValue aggregationTarget = (aggregationLevel == AggregationLevel.DATABASE) ? new BsonInt32(1) : new BsonString(namespace.getCollectionName()); BsonDocument commandDocument = new BsonDocument("aggregate", aggregationTarget); 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()); } if (comment != null) { commandDocument.put("comment", new BsonString(comment)); } if (hint != null) { commandDocument.put("hint", hint); } return commandDocument; }
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()); } if (hint != null) { commandDocument.put("hint", hint); } return commandDocument; }
private BsonDocument getCommand(final ConnectionDescription description) { BsonDocument outputDocument = new BsonDocument(getAction(), new BsonString(getCollectionName())); outputDocument.append("sharded", BsonBoolean.valueOf(isSharded())); outputDocument.append("nonAtomic", BsonBoolean.valueOf(isNonAtomic())); if (getDatabaseName() != null) { outputDocument.put("db", new BsonString(getDatabaseName())); } BsonDocument commandDocument = new BsonDocument("mapreduce", new BsonString(namespace.getCollectionName())) .append("map", getMapFunction()) .append("reduce", getReduceFunction()) .append("out", outputDocument) .append("query", asValueOrNull(getFilter())) .append("sort", asValueOrNull(getSort())) .append("finalize", asValueOrNull(getFinalizeFunction())) .append("scope", asValueOrNull(getScope())) .append("verbose", BsonBoolean.valueOf(isVerbose())); putIfNotZero(commandDocument, "limit", getLimit()); putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS)); putIfTrue(commandDocument, "jsMode", isJsMode()); if (bypassDocumentValidation != null && description != null && serverIsAtLeastVersionThreeDotTwo(description)) { commandDocument.put("bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation)); } if (description != null) { appendWriteConcernToCommand(writeConcern, commandDocument, description); } if (collation != null) { commandDocument.put("collation", collation.asDocument()); } return commandDocument; }
private BsonDocument getCommand(final ConnectionDescription description, final SessionContext sessionContext) { BsonDocument commandDocument = new BsonDocument("aggregate", aggregateTarget.create()); appendReadConcernToCommand(sessionContext, commandDocument); commandDocument.put("pipeline", pipelineCreator.create(description, sessionContext)); if (maxTimeMS > 0) { commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS)); } if (!isInline(description)) { 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); } return commandDocument; }
private BsonDocument getCommand(final ConnectionDescription description) { BsonDocument document = new BsonDocument("create", new BsonString(collectionName)); putIfFalse(document, "autoIndexId", autoIndex); document.put("capped", BsonBoolean.valueOf(capped)); if (capped) { putIfNotZero(document, "size", sizeInBytes);
@Override public BsonDocument create(final ServerDescription serverDescription, final ConnectionDescription connectionDescription) { validateCollation(connectionDescription, collation); BsonDocument commandDocument = new BsonDocument("findAndModify", new BsonString(getNamespace().getCollectionName())); putIfNotNull(commandDocument, "query", getFilter()); putIfNotNull(commandDocument, "fields", getProjection()); putIfNotNull(commandDocument, "sort", getSort()); commandDocument.put("new", new BsonBoolean(!isReturnOriginal())); putIfTrue(commandDocument, "upsert", isUpsert()); putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS)); commandDocument.put("update", getReplacement()); if (bypassDocumentValidation != null && serverIsAtLeastVersionThreeDotTwo(connectionDescription)) { commandDocument.put("bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation)); } addWriteConcernToCommand(connectionDescription, commandDocument, sessionContext); if (collation != null) { commandDocument.put("collation", collation.asDocument()); } addTxnNumberToCommand(serverDescription, connectionDescription, commandDocument, sessionContext); return commandDocument; } };
@Override public BsonDocument create(final ServerDescription serverDescription, final ConnectionDescription connectionDescription) { validateCollation(connectionDescription, collation); BsonDocument commandDocument = new BsonDocument("findAndModify", new BsonString(getNamespace().getCollectionName())); putIfNotNull(commandDocument, "query", getFilter()); putIfNotNull(commandDocument, "fields", getProjection()); putIfNotNull(commandDocument, "sort", getSort()); commandDocument.put("new", new BsonBoolean(!isReturnOriginal())); putIfTrue(commandDocument, "upsert", isUpsert()); putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS)); commandDocument.put("update", getUpdate()); if (bypassDocumentValidation != null && serverIsAtLeastVersionThreeDotTwo(connectionDescription)) { commandDocument.put("bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation)); } addWriteConcernToCommand(connectionDescription, commandDocument, sessionContext); if (collation != null) { commandDocument.put("collation", collation.asDocument()); } if (arrayFilters != null) { commandDocument.put("arrayFilters", new BsonArray(arrayFilters)); } addTxnNumberToCommand(serverDescription, connectionDescription, commandDocument, sessionContext); return commandDocument; } };
private BsonDocument getCommand(final SessionContext sessionContext) { BsonDocument commandDocument = new BsonDocument("mapreduce", new BsonString(namespace.getCollectionName())) .append("map", getMapFunction()) .append("reduce", getReduceFunction()) .append("out", new BsonDocument("inline", new BsonInt32(1))) .append("query", asValueOrNull(getFilter())) .append("sort", asValueOrNull(getSort())) .append("finalize", asValueOrNull(getFinalizeFunction())) .append("scope", asValueOrNull(getScope())) .append("verbose", BsonBoolean.valueOf(isVerbose())); appendReadConcernToCommand(sessionContext, commandDocument); putIfNotZero(commandDocument, "limit", getLimit()); putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS)); putIfTrue(commandDocument, "jsMode", isJsMode()); if (collation != null) { commandDocument.put("collation", collation.asDocument()); } return commandDocument; }
private void addJ(final BsonDocument document) { if (journal != null) { document.put("j", BsonBoolean.valueOf(journal)); } }