Refine search
/** * Creates a $count pipeline stage using the named field to store the result * * @param field the field in which to store the count * @return the $count pipeline stage * @mongodb.driver.manual reference/operator/aggregation/count/ $count * @mongodb.server.release 3.4 * @since 3.4 */ public static Bson count(final String field) { return new BsonDocument("$count", new BsonString(field)); }
/** * 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} * @return the $unwind pipeline stage * @mongodb.driver.manual reference/operator/aggregation/unwind/ $unwind */ public static Bson unwind(final String fieldName) { return new BsonDocument("$unwind", new BsonString(fieldName)); }
/** * Creates a $out pipeline stage for the specified filter * * @param collectionName the collection name * @return the $out pipeline stage * @mongodb.driver.manual reference/operator/aggregation/out/ $out * @mongodb.server.release 2.6 */ public static Bson out(final String collectionName) { return new BsonDocument("$out", new BsonString(collectionName)); }
/** * Creates a projection to the given field name of the textScore, for use with text queries. * * @param fieldName the field name * @return the projection * @mongodb.driver.manual reference/operator/projection/meta/#projection textScore */ public static Bson metaTextScore(final String fieldName) { return new BsonDocument(fieldName, new BsonDocument("$meta", new BsonString("textScore"))); }
/** * Create a sort specification for the text score meta projection on the given field. * * @param fieldName the field name * @return the sort specification * @mongodb.driver.manual reference/operator/projection/meta/#sort textScore */ public static Bson metaTextScore(final String fieldName) { return new BsonDocument(fieldName, new BsonDocument("$meta", new BsonString("textScore"))); }
/** * Creates an update that sets the value of the field to the current date as a BSON timestamp. * * @param fieldName the non-null field name * @return the update * @mongodb.driver.manual reference/operator/update/currentDate/ $currentDate * @mongodb.driver.manual reference/bson-types/#document-bson-type-timestamp Timestamp */ public static Bson currentTimestamp(final String fieldName) { return new SimpleUpdate<BsonDocument>(fieldName, new BsonDocument("$type", new BsonString("timestamp")), "$currentDate"); }
private BsonDocument getCommand(final ConnectionDescription description) { BsonDocument commandDocument = new BsonDocument("dropUser", new BsonString(userName)); appendWriteConcernToCommand(writeConcern, commandDocument, description); return commandDocument; } }
/** * Create an index key for a text index on the given field. * * @param fieldName the field to create a text index on * @return the index specification * @mongodb.driver.manual core/text text index */ public static Bson text(final String fieldName) { notNull("fieldName", fieldName); return new BsonDocument(fieldName, new BsonString("text")); }
/** * Creates a filter that matches all documents for which the given expression is true. * * @param javaScriptExpression the JavaScript expression * @return the filter * @mongodb.driver.manual reference/operator/query/where $where */ public static Bson where(final String javaScriptExpression) { notNull("javaScriptExpression", javaScriptExpression); return new BsonDocument("$where", new BsonString(javaScriptExpression)); }
/** * Create an index key for a hashed index on the given field. * * @param fieldName the field to create a hashed index on * @return the index specification * @mongodb.driver.manual core/hashed hashed index */ public static Bson hashed(final String fieldName) { notNull("fieldName", fieldName); return new BsonDocument(fieldName, new BsonString("hashed")); }
private BsonDocument getCommand(final ConnectionDescription description) { BsonDocument commandDocument = new BsonDocument("drop", new BsonString(namespace.getCollectionName())); appendWriteConcernToCommand(writeConcern, commandDocument, description); return commandDocument; }
private void executeRename(@Nullable final ClientSession clientSession, final BsonValue id, final String newFilename) { UpdateResult updateResult; if (clientSession != null) { updateResult = filesCollection.updateOne(clientSession, new BsonDocument("_id", id), new BsonDocument("$set", new BsonDocument("filename", new BsonString(newFilename)))); } else { updateResult = filesCollection.updateOne(new BsonDocument("_id", id), new BsonDocument("$set", new BsonDocument("filename", new BsonString(newFilename)))); } if (updateResult.wasAcknowledged() && updateResult.getMatchedCount() == 0) { throw new MongoGridFSException(format("No file found with the id: %s", id)); } }
private static BsonDocument namespaceToDocument(final MongoNamespace namespace) { Assertions.notNull("namespace", namespace); return new BsonDocument("db", new BsonString(namespace.getDatabaseName())) .append("coll", new BsonString(namespace.getCollectionName())); }
private BsonDocument getCommand(final ConnectionDescription description) { BsonDocument command = new BsonDocument("dropIndexes", new BsonString(namespace.getCollectionName())); if (indexName != null) { command.put("index", new BsonString(indexName)); } else { command.put("index", indexKeys); } putIfNotZero(command, "maxTimeMS", maxTimeMS); appendWriteConcernToCommand(writeConcern, command, description); return command; } }
/** * Gets this read concern as a document. * * @return The read concern as a BsonDocument */ public BsonDocument asDocument() { BsonDocument readConcern = new BsonDocument(); if (level != null) { readConcern.put("level", new BsonString(level.getValue())); } return readConcern; }
public static BsonDocument getAuthCommand(final String userName, final String authHash, final String nonce) { String key = nonce + userName + authHash; BsonDocument cmd = new BsonDocument(); cmd.put("authenticate", new BsonInt32(1)); cmd.put("user", new BsonString(userName)); cmd.put("nonce", new BsonString(nonce)); cmd.put("key", new BsonString(hexMD5(key.getBytes(UTF_8_CHARSET)))); return cmd; }
private BsonDocument asQueryDocument(final ConnectionDescription connectionDescription, final ReadPreference readPreference) { BsonDocument document = new BsonDocument("$query", new BsonDocument("ns", new BsonString(namespace.getFullName()))); if (maxTimeMS > 0) { document.put("$maxTimeMS", new BsonInt64(maxTimeMS)); } if (connectionDescription.getServerType() == SHARD_ROUTER && !readPreference.equals(primary())) { document.put("$readPreference", readPreference.toDocument()); } return document; }
/** * The collStats command returns a variety of storage statistics for a given collection * * @return a CommandResult containing the statistics about this collection * @mongodb.driver.manual reference/command/collStats/ collStats Command */ public CommandResult getStats() { return getDB().executeCommand(new BsonDocument("collStats", new BsonString(getName())), getReadPreference()); }
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; } }
private BsonDocument getCommand(final ConnectionDescription description) { BsonDocument commandDocument = new BsonDocument("create", new BsonString(viewName)) .append("viewOn", new BsonString(viewOn)) .append("pipeline", new BsonArray(pipeline)); if (collation != null) { commandDocument.put("collation", collation.asDocument()); } appendWriteConcernToCommand(writeConcern, commandDocument, description); return commandDocument; }