org.springframework.data.mongodb.core.query

Class Query

  • Direct Known Subclasses:
    BasicQuery, TextQuery


    public class Query
    extends Object
    MongoDB Query object representing criteria, projection, sorting and query hints.
    Author:
    Thomas Risberg, Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch
    • Constructor Detail

      • Query

        public Query()
    • Method Detail

      • fields

        public Field fields()
      • skip

        public Query skip(long skip)
        Set number of documents to skip before returning results.
        Parameters:
        skip -
        Returns:
      • limit

        public Query limit(int limit)
        Limit the number of returned documents to limit.
        Parameters:
        limit -
        Returns:
      • withHint

        public Query withHint(String name)
        Configures the query to use the given hint when being executed.
        Parameters:
        name - must not be null or empty.
        Returns:
      • with

        public Query with(Pageable pageable)
        Sets the given pagination information on the Query instance. Will transparently set skip and limit as well as applying the Sort instance defined with the Pageable.
        Parameters:
        pageable -
        Returns:
      • with

        public Query with(Sort sort)
        Adds a Sort to the Query instance.
        Parameters:
        sort -
        Returns:
      • getRestrictedTypes

        public Set<Class<?>> getRestrictedTypes()
        Returns:
        the restrictedTypes
      • restrict

        public Query restrict(Class<?> type,
                              Class<?>... additionalTypes)
        Restricts the query to only return documents instances that are exactly of the given types.
        Parameters:
        type - may not be null
        additionalTypes - may not be null
        Returns:
      • getQueryObject

        public org.bson.Document getQueryObject()
        Returns:
        the query Document.
      • getFieldsObject

        public org.bson.Document getFieldsObject()
        Returns:
        the field Document.
      • getSortObject

        public org.bson.Document getSortObject()
        Returns:
        the sort Document.
      • getSkip

        public long getSkip()
        Get the number of documents to skip.
        Returns:
      • getLimit

        public int getLimit()
        Get the maximum number of documents to be return.
        Returns:
      • maxScan

        @Deprecated
        public Query maxScan(long maxScan)
        Deprecated. since 2.1 due to deprecation in MongoDB 4.0.
        Parameters:
        maxScan -
        Returns:
        this.
        Since:
        1.6
        See Also:
        Meta.setMaxScan(long)
      • comment

        public Query comment(String comment)
        Add a comment to the query that is propagated to the profile log.
        Parameters:
        comment -
        Returns:
        this.
        Since:
        1.6
        See Also:
        Meta.setComment(String)
      • cursorBatchSize

        public Query cursorBatchSize(int batchSize)
        Set the number of documents to return in each response batch.
        Use 0 (zero) for no limit. A negative limit closes the cursor after returning a single batch indicating to the server that the client will not ask for a subsequent one.
        Parameters:
        batchSize - The number of documents to return per batch.
        Returns:
        this.
        Since:
        2.1
        See Also:
        Meta.setCursorBatchSize(int)
      • getMeta

        public Meta getMeta()
        Returns:
        never null.ΓΈ
        Since:
        1.6
      • setMeta

        public void setMeta(Meta meta)
        Parameters:
        meta - must not be null.
        Since:
        1.6
      • collation

        public Query collation(@Nullable
                               Collation collation)
        Set the Collation applying language-specific rules for string comparison.
        Parameters:
        collation - can be null.
        Returns:
        Since:
        2.0
      • getCollation

        public Optional<Collation> getCollation()
        Get the Collation defining language-specific rules for string comparison.
        Returns:
        Since:
        2.0
      • querySettingsEquals

        protected boolean querySettingsEquals(Query that)
        Tests whether the settings of the given Query are equal to this query.
        Parameters:
        that -
        Returns:
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isRestrictedTypeKey

        @Deprecated
        public static boolean isRestrictedTypeKey(String key)
        Deprecated. don't call this method as the restricted type handling will undergo some significant changes going forward.
        Returns whether the given key is the one used to hold the type restriction information.
        Parameters:
        key -
        Returns: