Refine search
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; }
document.put("$orderby", sort); document.put("$maxTimeMS", new BsonInt64(maxTimeMS)); document.put("$readPreference", readPreference.toDocument()); document.put("$comment", new BsonString(comment)); document.put("$hint", hint); document.put("$max", max); document.put("$min", min); document.put("$maxScan", new BsonInt64(maxScan)); document.put("$returnKey", BsonBoolean.TRUE); document.put("$showDiskLoc", BsonBoolean.TRUE); document.put("$snapshot", BsonBoolean.TRUE); document = filter != null ? filter : new BsonDocument(); } else if (filter != null) { document.put("$query", filter); } else if (!document.containsKey("$query")) { document.put("$query", new BsonDocument());
private BsonDocument getAuthCommand(final String userName) { BsonDocument cmd = new BsonDocument(); cmd.put("authenticate", new BsonInt32(1)); if (userName != null) { cmd.put("user", new BsonString(userName)); } cmd.put("mechanism", new BsonString(AuthenticationMechanism.MONGODB_X509.getMechanismName())); return cmd; }
@Override @SuppressWarnings("deprecation") public void encode(final BsonWriter writer, final GridFSFile value, final EncoderContext encoderContext) { BsonDocument bsonDocument = new BsonDocument(); bsonDocument.put("_id", value.getId()); bsonDocument.put("filename", new BsonString(value.getFilename())); bsonDocument.put("length", new BsonInt64(value.getLength())); bsonDocument.put("chunkSize", new BsonInt32(value.getChunkSize())); bsonDocument.put("uploadDate", new BsonDateTime(value.getUploadDate().getTime())); if (value.getMD5() != null) { bsonDocument.put("md5", new BsonString(value.getMD5())); } Document metadata = value.getMetadata(); if (metadata != null) { bsonDocument.put("metadata", new BsonDocumentWrapper<Document>(metadata, documentCodec)); } Document extraElements = value.getExtraElements(); if (extraElements != null) { bsonDocument.putAll(new BsonDocumentWrapper<Document>(extraElements, documentCodec)); } bsonDocumentCodec.encode(writer, bsonDocument, encoderContext); }
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; } }
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; }
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 manufactureGetLastErrorResponse(final MongoBulkWriteException e) { BsonDocument response = new BsonDocument(); addBulkWriteResultToResponse(e.getWriteResult(), response); if (e.getWriteConcernError() != null) { response.putAll(e.getWriteConcernError().getDetails()); } if (getLastError(e) != null) { response.put("err", new BsonString(getLastError(e).getMessage())); response.put("code", new BsonInt32(getLastError(e).getCode())); response.putAll(getLastError(e).getDetails()); } else if (e.getWriteConcernError() != null) { response.put("err", new BsonString(e.getWriteConcernError().getMessage())); response.put("code", new BsonInt32(e.getWriteConcernError().getCode())); } return response; }
/** * 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; }
@Override public BsonDocument toDocument() { BsonDocument readPrefObject = new BsonDocument("mode", new BsonString(getName())); if (!tagSetList.isEmpty()) { readPrefObject.put("tags", tagsListToBsonArray()); } if (maxStalenessMS != null) { readPrefObject.put("maxStalenessSeconds", new BsonInt64(MILLISECONDS.toSeconds(maxStalenessMS))); } return readPrefObject; }
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 void promoteRenderableToDollarForm(final BsonDocument document, final Map.Entry<String, BsonValue> clause) { BsonArray clauses = new BsonArray(); for (Map.Entry<String, BsonValue> queryElement : document.entrySet()) { clauses.add(new BsonDocument(queryElement.getKey(), queryElement.getValue())); } clauses.add(new BsonDocument(clause.getKey(), clause.getValue())); document.clear(); document.put("$and", clauses); }
@Override public BsonDocument clone() { BsonDocument to = new BsonDocument(); for (Entry<String, BsonValue> cur : entrySet()) { switch (cur.getValue().getBsonType()) { case DOCUMENT: to.put(cur.getKey(), cur.getValue().asDocument().clone()); break; case ARRAY: to.put(cur.getKey(), cur.getValue().asArray().clone()); break; case BINARY: to.put(cur.getKey(), BsonBinary.clone(cur.getValue().asBinary())); break; case JAVASCRIPT_WITH_SCOPE: to.put(cur.getKey(), BsonJavaScriptWithScope.clone(cur.getValue().asJavaScriptWithScope())); break; default: to.put(cur.getKey(), cur.getValue()); } } return to; }
@Override public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) { BsonDocument orRenderable = new BsonDocument(); BsonArray filtersArray = new BsonArray(); for (Bson filter : filters) { filtersArray.add(filter.toBsonDocument(documentClass, codecRegistry)); } orRenderable.put(operator.name, filtersArray); return orRenderable; }
private BsonDocument toDocument(final TagSet tagSet) { BsonDocument document = new BsonDocument(); for (Tag tag : tagSet) { document.put(tag.getName(), new BsonString(tag.getValue())); } return document; }
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 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; }
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(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; } }
putIfNotNullOrEmpty(commandDocument, "projection", projection); if (skip > 0) { commandDocument.put("skip", new BsonInt32(skip)); commandDocument.put("limit", new BsonInt32(Math.abs(limit))); commandDocument.put("limit", new BsonInt32(Math.abs(batchSize))); } else if (batchSize != 0) { commandDocument.put("batchSize", new BsonInt32(Math.abs(batchSize))); commandDocument.put("singleBatch", BsonBoolean.TRUE); commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS)); commandDocument.put("tailable", BsonBoolean.TRUE); commandDocument.put("awaitData", BsonBoolean.TRUE); commandDocument.put("oplogReplay", BsonBoolean.TRUE); commandDocument.put("noCursorTimeout", BsonBoolean.TRUE); commandDocument.put("allowPartialResults", BsonBoolean.TRUE); commandDocument.put("collation", collation.asDocument()); commandDocument.put("comment", new BsonString(comment)); commandDocument.put("hint", hint);