com.mongodb.reactivestreams.client.FindPublisher Maven / Gradle / Ivy
Show all versions of mongodb-driver-reactivestreams Show documentation
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mongodb.reactivestreams.client;
import com.mongodb.CursorType;
import com.mongodb.ExplainVerbosity;
import com.mongodb.annotations.Alpha;
import com.mongodb.annotations.Reason;
import com.mongodb.client.cursor.TimeoutMode;
import com.mongodb.client.model.Collation;
import com.mongodb.client.model.Projections;
import com.mongodb.lang.Nullable;
import org.bson.BsonValue;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.reactivestreams.Publisher;
import java.util.concurrent.TimeUnit;
/**
* Publisher interface for find.
*
* @param The type of the result.
* @since 1.0
*/
public interface FindPublisher extends Publisher {
/**
* Helper to return a publisher limited to the first result.
*
* @return a Publisher which will contain a single item.
*/
Publisher first();
/**
* Sets the query filter to apply to the query.
*
* @param filter the filter, which may be null.
* @return this
* @mongodb.driver.manual reference/method/db.collection.find/ Filter
*/
FindPublisher filter(@Nullable Bson filter);
/**
* Sets the limit to apply.
*
* @param limit the limit
* @return this
* @mongodb.driver.manual reference/method/cursor.limit/#cursor.limit Limit
*/
FindPublisher limit(int limit);
/**
* Sets the number of documents to skip.
*
* @param skip the number of documents to skip
* @return this
* @mongodb.driver.manual reference/method/cursor.skip/#cursor.skip Skip
*/
FindPublisher skip(int skip);
/**
* Sets the maximum execution time on the server for this operation.
*
* @param maxTime the max time
* @param timeUnit the time unit, which may not be null
* @return this
* @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
*/
FindPublisher maxTime(long maxTime, TimeUnit timeUnit);
/**
* The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor
* query. This only applies to a TAILABLE_AWAIT cursor. When the cursor is not a TAILABLE_AWAIT cursor,
* this option is ignored.
*
* On servers >= 3.2, this option will be specified on the getMore command as "maxTimeMS". The default
* is no value: no "maxTimeMS" is sent to the server with the getMore command.
*
* On servers < 3.2, this option is ignored, and indicates that the driver should respect the server's default value
*
* A zero value will be ignored.
*
* @param maxAwaitTime the max await time
* @param timeUnit the time unit to return the result in
* @return the maximum await execution time in the given time unit
* @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
* @since 1.2
*/
FindPublisher maxAwaitTime(long maxAwaitTime, TimeUnit timeUnit);
/**
* Sets a document describing the fields to return for all matching documents.
*
* @param projection the project document, which may be null.
* @return this
* @mongodb.driver.manual reference/method/db.collection.find/ Projection
* @see Projections
*/
FindPublisher projection(@Nullable Bson projection);
/**
* Sets the sort criteria to apply to the query.
*
* @param sort the sort criteria, which may be null.
* @return this
* @mongodb.driver.manual reference/method/cursor.sort/ Sort
*/
FindPublisher sort(@Nullable Bson sort);
/**
* The server normally times out idle cursors after an inactivity period (10 minutes)
* to prevent excess memory use. Set this option to prevent that.
*
* @param noCursorTimeout true if cursor timeout is disabled
* @return this
*/
FindPublisher noCursorTimeout(boolean noCursorTimeout);
/**
* Get partial results from a sharded cluster if one or more shards are unreachable (instead of throwing an error).
*
* @param partial if partial results for sharded clusters is enabled
* @return this
*/
FindPublisher partial(boolean partial);
/**
* Sets the cursor type.
*
* @param cursorType the cursor type
* @return this
*/
FindPublisher cursorType(CursorType cursorType);
/**
* Sets the collation options
*
* A null value represents the server default.
* @param collation the collation options to use
* @return this
* @since 1.3
* @mongodb.server.release 3.4
*/
FindPublisher collation(@Nullable Collation collation);
/**
* Sets the comment to the query. A null value means no comment is set.
*
* @param comment the comment
* @return this
* @since 1.6
*/
FindPublisher comment(@Nullable String comment);
/**
* Sets the comment for this operation. A null value means no comment is set.
*
* The comment can be any valid BSON type for server versions 4.4 and above.
* Server versions between 3.6 and 4.2 only support string as comment,
* and providing a non-string type will result in a server-side error.
*
* @param comment the comment
* @return this
* @since 4.6
* @mongodb.server.release 3.6
*/
FindPublisher comment(@Nullable BsonValue comment);
/**
* Sets the hint for which index to use. A null value means no hint is set.
*
* @param hint the hint
* @return this
* @since 1.6
*/
FindPublisher hint(@Nullable Bson hint);
/**
* Sets the hint for which index to use. A null value means no hint is set.
*
* @param hint the name of the index which should be used for the operation
* @return this
* @since 1.13
*/
FindPublisher hintString(@Nullable String hint);
/**
* Add top-level variables to the operation. A null value means no variables are set.
*
* Allows for improved command readability by separating the variables from the query text.
*
* @param variables for find operation or null
* @return this
* @mongodb.driver.manual reference/command/find/
* @mongodb.server.release 5.0
* @since 4.6
*/
FindPublisher let(@Nullable Bson variables);
/**
* Sets the exclusive upper bound for a specific index. A null value means no max is set.
*
* @param max the max
* @return this
* @since 1.6
*/
FindPublisher max(@Nullable Bson max);
/**
* Sets the minimum inclusive lower bound for a specific index. A null value means no max is set.
*
* @param min the min
* @return this
* @since 1.6
*/
FindPublisher min(@Nullable Bson min);
/**
* Sets the returnKey. If true the find operation will return only the index keys in the resulting documents.
*
* @param returnKey the returnKey
* @return this
* @since 1.6
*/
FindPublisher returnKey(boolean returnKey);
/**
* Sets the showRecordId. Set to true to add a field {@code $recordId} to the returned documents.
*
* @param showRecordId the showRecordId
* @return this
* @since 1.6
*/
FindPublisher showRecordId(boolean showRecordId);
/**
* Sets the number of documents to return per batch.
*
* Overrides the {@link org.reactivestreams.Subscription#request(long)} value for setting the batch size, allowing for fine-grained
* control over the underlying cursor.
*
* @param batchSize the batch size
* @return this
* @since 1.8
* @mongodb.driver.manual reference/method/cursor.batchSize/#cursor.batchSize Batch Size
*/
FindPublisher batchSize(int batchSize);
/**
* Enables writing to temporary files on the server. When set to true, the server
* can write temporary data to disk while executing the find operation.
*
* This option is sent only if the caller explicitly sets it to true.
*
* @param allowDiskUse the allowDiskUse
* @return this
* @since 4.1
* @mongodb.server.release 4.4
*/
FindPublisher allowDiskUse(@Nullable Boolean allowDiskUse);
/**
* Sets the timeoutMode for the cursor.
*
*
* Requires the {@code timeout} to be set, either in the {@link com.mongodb.MongoClientSettings},
* via {@link MongoDatabase} or via {@link MongoCollection}
*
*
* If the {@code timeout} is set then:
*
* - For non-tailable cursors, the default value of timeoutMode is {@link TimeoutMode#CURSOR_LIFETIME}
* - For tailable cursors, the default value of timeoutMode is {@link TimeoutMode#ITERATION} and its an error
* to configure it as: {@link TimeoutMode#CURSOR_LIFETIME}
*
* @param timeoutMode the timeout mode
* @return this
* @since 5.2
*/
@Alpha(Reason.CLIENT)
FindPublisher timeoutMode(TimeoutMode timeoutMode);
/**
* Explain the execution plan for this operation with the server's default verbosity level
*
* @return the execution plan
* @since 4.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.2
*/
Publisher explain();
/**
* Explain the execution plan for this operation with the given verbosity level
*
* @param verbosity the verbosity of the explanation
* @return the execution plan
* @since 4.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.2
*/
Publisher explain(ExplainVerbosity verbosity);
/**
* Explain the execution plan for this operation with the server's default verbosity level
*
* @param the type of the document class
* @param explainResultClass the document class to decode into
* @return the execution plan
* @since 4.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.2
*/
Publisher explain(Class explainResultClass);
/**
* Explain the execution plan for this operation with the given verbosity level
*
* @param the type of the document class
* @param explainResultClass the document class to decode into
* @param verbosity the verbosity of the explanation
* @return the execution plan
* @since 4.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.2
*/
Publisher explain(Class explainResultClass, ExplainVerbosity verbosity);
}