Class DBCollectionFindOptions


  • public final class DBCollectionFindOptions
    extends java.lang.Object
    The options to apply to a find operation (also commonly referred to as a query).
    Since:
    3.4
    • Constructor Detail

      • DBCollectionFindOptions

        public DBCollectionFindOptions()
        Construct a new instance
    • Method Detail

      • copy

        public DBCollectionFindOptions copy()
        Copy this DBCollectionFindOptions instance into a new instance.
        Returns:
        the new DBCollectionFindOptions with the same settings as this instance.
      • getLimit

        public int getLimit()
        Gets the limit to apply. The default is null.
        Returns:
        the limit
      • limit

        public DBCollectionFindOptions limit​(int limit)
        Sets the limit to apply.
        Parameters:
        limit - the limit, which may be null
        Returns:
        this
      • getSkip

        public int getSkip()
        Gets the number of documents to skip. The default is 0.
        Returns:
        the number of documents to skip, which may be null
      • skip

        public DBCollectionFindOptions skip​(int skip)
        Sets the number of documents to skip.
        Parameters:
        skip - the number of documents to skip
        Returns:
        this
      • getMaxTime

        public long getMaxTime​(java.util.concurrent.TimeUnit timeUnit)
        Gets the maximum execution time on the server for this operation. The default is 0, which places no limit on the execution time.
        Parameters:
        timeUnit - the time unit to return the result in
        Returns:
        the maximum execution time in the given time unit
      • maxTime

        public DBCollectionFindOptions maxTime​(long maxTime,
                                               java.util.concurrent.TimeUnit timeUnit)
        Sets the maximum execution time on the server for this operation.
        Parameters:
        maxTime - the max time
        timeUnit - the time unit, which may not be null
        Returns:
        this
      • getMaxAwaitTime

        public long getMaxAwaitTime​(java.util.concurrent.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.
        Parameters:
        timeUnit - the time unit to return the result in
        Returns:
        the maximum await execution time in the given time unit
      • maxAwaitTime

        public DBCollectionFindOptions maxAwaitTime​(long maxAwaitTime,
                                                    java.util.concurrent.TimeUnit timeUnit)
        Sets the maximum await execution time on the server for this operation.
        Parameters:
        maxAwaitTime - the max await time. A zero value will be ignored, and indicates that the driver should respect the server's default value
        timeUnit - the time unit, which may not be null
        Returns:
        this
      • getBatchSize

        public int getBatchSize()
        Gets the number of documents to return per batch. Default to 0, which indicates that the server chooses an appropriate batch size.
        Returns:
        the batch size, which may be null
      • batchSize

        public DBCollectionFindOptions batchSize​(int batchSize)
        Sets the number of documents to return per batch.
        Parameters:
        batchSize - the batch size
        Returns:
        this
      • getModifiers

        public DBObject getModifiers()
        Gets the query modifiers to apply to this operation. The default is not to apply any modifiers.
        Returns:
        the query modifiers, which may be null
      • modifiers

        public DBCollectionFindOptions modifiers​(@Nullable
                                                 DBObject modifiers)
        Sets the query modifiers to apply to this operation.
        Parameters:
        modifiers - the query modifiers to apply, which may be null.
        Returns:
        this
      • getProjection

        @Nullable
        public DBObject getProjection()
        Gets a document describing the fields to return for all matching documents.
        Returns:
        the project document, which may be null
      • projection

        public DBCollectionFindOptions projection​(@Nullable
                                                  DBObject projection)
        Sets a document describing the fields to return for all matching documents.
        Parameters:
        projection - the project document, which may be null.
        Returns:
        this
      • getSort

        @Nullable
        public DBObject getSort()
        Gets the sort criteria to apply to the query. The default is null, which means that the documents will be returned in an undefined order.
        Returns:
        a document describing the sort criteria
      • sort

        public DBCollectionFindOptions sort​(@Nullable
                                            DBObject sort)
        Sets the sort criteria to apply to the query.
        Parameters:
        sort - the sort criteria, which may be null.
        Returns:
        this
      • isNoCursorTimeout

        public boolean isNoCursorTimeout()
        The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. If true, that timeout is disabled.
        Returns:
        true if cursor timeout is disabled
      • noCursorTimeout

        public DBCollectionFindOptions noCursorTimeout​(boolean noCursorTimeout)
        The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
        Parameters:
        noCursorTimeout - true if cursor timeout is disabled
        Returns:
        this
      • isOplogReplay

        public boolean isOplogReplay()
        Users should not set this under normal circumstances.
        Returns:
        if oplog replay is enabled
      • oplogReplay

        public DBCollectionFindOptions oplogReplay​(boolean oplogReplay)
        Users should not set this under normal circumstances.
        Parameters:
        oplogReplay - if oplog replay is enabled
        Returns:
        this
      • isPartial

        public boolean isPartial()
        Get partial results from a sharded cluster if one or more shards are unreachable (instead of throwing an error).
        Returns:
        if partial results for sharded clusters is enabled
      • partial

        public DBCollectionFindOptions partial​(boolean partial)
        Get partial results from a sharded cluster if one or more shards are unreachable (instead of throwing an error).
        Parameters:
        partial - if partial results for sharded clusters is enabled
        Returns:
        this
      • getCursorType

        public CursorType getCursorType()
        Get the cursor type.
        Returns:
        the cursor type
      • getReadPreference

        @Nullable
        public ReadPreference getReadPreference()
        Returns the readPreference
        Returns:
        the readPreference
      • readPreference

        public DBCollectionFindOptions readPreference​(@Nullable
                                                      ReadPreference readPreference)
        Sets the readPreference
        Parameters:
        readPreference - the readPreference
        Returns:
        this
      • getReadConcern

        @Nullable
        public ReadConcern getReadConcern()
        Returns the readConcern
        Returns:
        the readConcern
      • readConcern

        public DBCollectionFindOptions readConcern​(@Nullable
                                                   ReadConcern readConcern)
        Sets the readConcern
        Parameters:
        readConcern - the readConcern
        Returns:
        this
      • getCollation

        @Nullable
        public Collation getCollation()
        Returns the collation options
        Returns:
        the collation options
      • collation

        public DBCollectionFindOptions collation​(@Nullable
                                                 Collation collation)
        Sets the collation
        Parameters:
        collation - the collation
        Returns:
        this