Refine search
/** * Creates a $skip pipeline stage * * @param skip the number of documents to skip * @return the $skip pipeline stage * @mongodb.driver.manual reference/operator/aggregation/skip/ $skip */ public static Bson skip(final int skip) { return new BsonDocument("$skip", new BsonInt32(skip)); }
/** * Creates a projection that excludes the _id field. This suppresses the automatic inclusion of _id that is the default, even when * other fields are explicitly included. * * @return the projection */ public static Bson excludeId() { return new BsonDocument("_id", new BsonInt32(0)); }
/** * Creates a projection that includes for the given field only the first element of an array that matches the query filter. This is * referred to as the positional $ operator. * * @param fieldName the field name whose value is the array * @return the projection * @mongodb.driver.manual reference/operator/projection/positional/#projection Project the first matching element ($ operator) */ public static Bson elemMatch(final String fieldName) { return new BsonDocument(fieldName + ".$", new BsonInt32(1)); }
/** * Creates a $limit pipeline stage for the specified filter * * @param limit the limit * @return the $limit pipeline stage * @mongodb.driver.manual reference/operator/aggregation/limit/ $limit */ public static Bson limit(final int limit) { return new BsonDocument("$limit", new BsonInt32(limit)); }
public static BsonDocument getNonceCommand() { return new BsonDocument("getnonce", new BsonInt32(1)); }
private BsonDocument getResponseDocument() { return new BsonDocument("ok", new BsonInt32(1)); }
/** * Creates a $sample pipeline stage with the specified sample size * * @param size the sample size * @return the $sample pipeline stage * @mongodb.driver.manual reference/operator/aggregation/sample/ $sample * @mongodb.server.release 3.2 * @since 3.2 */ public static Bson sample(final int size) { return new BsonDocument("$sample", new BsonDocument("size", new BsonInt32(size))); }
/** * Creates a projection to the given field name of a slice of the array value of that field. * * @param fieldName the field name * @param limit the number of elements to project. * @return the projection * @mongodb.driver.manual reference/operator/projection/slice Slice */ public static Bson slice(final String fieldName, final int limit) { return new BsonDocument(fieldName, new BsonDocument("$slice", new BsonInt32(limit))); }
static BsonDocument getCursorDocumentFromBatchSize(final Integer batchSize) { return batchSize == null ? new BsonDocument() : new BsonDocument("batchSize", new BsonInt32(batchSize)); }
/** * Creates a projection to the given field name of a slice of the array value of that field. * * @param fieldName the field name * @param skip the number of elements to skip before applying the limit * @param limit the number of elements to project * @return the projection * @mongodb.driver.manual reference/operator/projection/slice Slice */ public static Bson slice(final String fieldName, final int skip, final int limit) { return new BsonDocument(fieldName, new BsonDocument("$slice", new BsonArray(asList(new BsonInt32(skip), new BsonInt32(limit))))); }
private BsonDocument getCommand(final ConnectionDescription description) { BsonDocument commandDocument = new BsonDocument("dropDatabase", new BsonInt32(1)); appendWriteConcernToCommand(writeConcern, commandDocument, description); return commandDocument; } }
/** * 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); }
private void completeConnectionDescriptionInitializationAsync(final InternalConnection internalConnection, final ConnectionDescription connectionDescription, final SingleResultCallback<ConnectionDescription> callback) { executeCommandAsync("admin", new BsonDocument("getlasterror", new BsonInt32(1)), internalConnection, new SingleResultCallback<BsonDocument>() { @Override public void onResult(final BsonDocument result, final Throwable t) { if (result == null) { callback.onResult(connectionDescription, null); } else { callback.onResult(applyGetLastErrorResult(result, connectionDescription), null); } } }); }
private ConnectionDescription completeConnectionDescriptionInitialization(final InternalConnection internalConnection, final ConnectionDescription connectionDescription) { return applyGetLastErrorResult(executeCommandWithoutCheckingForFailure("admin", new BsonDocument("getlasterror", new BsonInt32(1)), internalConnection), connectionDescription); }
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 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 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))); }
private BsonDocument createIsMasterCommand() { BsonDocument isMasterCommandDocument = new BsonDocument("ismaster", new BsonInt32(1)); isMasterCommandDocument.append("saslSupportedMechs", new BsonString(format("%s.%s", getMongoCredential().getSource(), getMongoCredential().getUserName()))); return isMasterCommandDocument; }
private BsonDocument getCommand() { BsonDocument command = new BsonDocument("listDatabases", new BsonInt32(1)); if (maxTimeMS > 0) { command.put("maxTimeMS", new BsonInt64(maxTimeMS)); } if (filter != null) { command.put("filter", filter); } if (nameOnly != null) { command.put("nameOnly", new BsonBoolean(nameOnly)); } return command; } }