/** * Creates a filter that matches all documents where the value of a field divided by a divisor has the specified remainder (i.e. perform * a modulo operation to select documents). * * @param fieldName the field name * @param divisor the modulus * @param remainder the remainder * @return the filter * @mongodb.driver.manual reference/operator/query/mod $mod */ public static Bson mod(final String fieldName, final long divisor, final long remainder) { return new OperatorFilter<BsonArray>("$mod", fieldName, new BsonArray(asList(new BsonInt64(divisor), new BsonInt64(remainder)))); }
static void putIfNotZero(final BsonDocument command, final String key, final long value) { if (value != 0) { command.put(key, new BsonInt64(value)); } } }
@Override public BsonInt64 decode(final BsonReader reader, final DecoderContext decoderContext) { return new BsonInt64(reader.readInt64()); }
@Override protected void doWriteInt64(final long value) { write(new BsonInt64(value)); }
private static Bson createBitUpdateDocument(final String fieldName, final String bitwiseOperator, final long value) { return createBitUpdateDocument(fieldName, bitwiseOperator, new BsonInt64(value)); }
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 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 BsonDocument asGetMoreCommandDocument() { return new BsonDocument(COMMAND_NAME, new BsonInt64(cursorId)) .append("collection", new BsonString(namespace.getCollectionName())) .append("batchSize", new BsonInt32(numberToReturn)); }
private BsonDocument asKillCursorsCommandDocument() { return new BsonDocument("killCursors", new BsonString(namespace.getCollectionName())) .append("cursors", new BsonArray(singletonList(new BsonInt64(serverCursor.getId())))); } }
private BsonDocument asKillCursorsCommandDocument(final ServerCursor localCursor) { return new BsonDocument("killCursors", new BsonString(namespace.getCollectionName())) .append("cursors", new BsonArray(singletonList(new BsonInt64(localCursor.getId())))); }
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; }
@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 asGetMoreCommandResponseDocument(final QueryResult<T> queryResult, final ResponseBuffers responseBuffers) { List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList(); if (responseBuffers.getReplyHeader().getNumberReturned() != 0) { responseBuffers.reset(); rawResultDocuments = ByteBufBsonDocument.createList(responseBuffers); } BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())) .append("ns", new BsonString(namespace.getFullName())) .append("nextBatch", new BsonArray(rawResultDocuments)); return new BsonDocument("cursor", cursorDocument) .append("ok", new BsonDouble(1)); }
protected void addTxnNumberToCommand(final ServerDescription serverDescription, final ConnectionDescription connectionDescription, final BsonDocument commandDocument, final SessionContext sessionContext) { if (isRetryableWrite(isRetryWrites(), getWriteConcern(), serverDescription, connectionDescription, sessionContext)) { commandDocument.put("txnNumber", new BsonInt64(sessionContext.advanceTransactionNumber())); } }
private BsonDocument asCommandResponseDocument() { BsonArray cursorIdArray = new BsonArray(); for (long cursorId : cursors) { cursorIdArray.add(new BsonInt64(cursorId)); } return new BsonDocument("ok", new BsonDouble(1)) .append("cursorsUnknown", cursorIdArray); }
private BsonDocument getCommand() { BsonDocument command = new BsonDocument("listIndexes", new BsonString(namespace.getCollectionName())) .append("cursor", getCursorDocumentFromBatchSize(batchSize == 0 ? null : batchSize)); if (maxTimeMS > 0) { command.put("maxTimeMS", new BsonInt64(maxTimeMS)); } return command; }
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("$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() { 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 asCommandDocument() { BsonArray array = new BsonArray(); for (long cursor : cursors) { array.add(new BsonInt64(cursor)); } return new BsonDocument(COMMAND_NAME, namespace == null ? new BsonInt32(1) : new BsonString(namespace.getCollectionName())) .append("cursors", array); }