Package org.mongojack

Class DBQuery


  • @Deprecated
    public class DBQuery
    extends Object
    Deprecated.
    Use com.mongodb.client.model.Filters
    Builder for MongoDB queries.

    It can be used in place of manually constructed queries (new Document("_id", "FOO")), but is now deprecated.

    Any values that are not basic objects (numbers, Strings, booleans, collections etc) that are passed in are attempted to be serialised using Jackson.

    Caution needs to be taken when querying entries that are objectIds. The mapper is at this stage unaware whether a field is stored as an ObjectId or not, so you must pass in any values that are stored as ObjectId as type ObjectId.

    The Query is a Bson, which makes it compatible with the methods in the JacksonMongoCollection that accept Bson-query objects, and makes those methods interoperable with Mongo's internal Filters class. But be warned that Query.initialize has to be called before Query.toBsonDocument, or exceptions will result. JacksonMongoCollection takes care of calling initialize for you.

    Since:
    1.2
    Author:
    James Roper
    • Constructor Detail

      • DBQuery

        public DBQuery()
        Deprecated.
    • Method Detail

      • empty

        public static DBQuery.Query empty()
        Deprecated.
        Create an empty query
        Returns:
        The empty query
      • is

        public static DBQuery.Query is​(String field,
                                       Object value)
        Deprecated.
        The field is equal to the given value
        Parameters:
        field - The field to compare
        value - The value to compare to
        Returns:
        the query
      • lessThan

        public static DBQuery.Query lessThan​(String field,
                                             Object value)
        Deprecated.
        The field is less than the given value
        Parameters:
        field - The field to compare
        value - The value to compare to
        Returns:
        the query
      • lessThanEquals

        public static DBQuery.Query lessThanEquals​(String field,
                                                   Object value)
        Deprecated.
        The field is less than or equal to the given value
        Parameters:
        field - The field to compare
        value - The value to compare to
        Returns:
        the query
      • greaterThan

        public static DBQuery.Query greaterThan​(String field,
                                                Object value)
        Deprecated.
        The field is greater than the given value
        Parameters:
        field - The field to compare
        value - The value to compare to
        Returns:
        the query
      • greaterThanEquals

        public static DBQuery.Query greaterThanEquals​(String field,
                                                      Object value)
        Deprecated.
        The field is greater than or equal to the given value
        Parameters:
        field - The field to compare
        value - The value to compare to
        Returns:
        the query
      • notEquals

        public static DBQuery.Query notEquals​(String field,
                                              Object value)
        Deprecated.
        The field is not equal to the given value
        Parameters:
        field - The field to compare
        value - The value to compare to
        Returns:
        the query
      • in

        public static DBQuery.Query in​(String field,
                                       Object... values)
        Deprecated.
        The field is in the given set of values
        Parameters:
        field - The field to compare
        values - The value to compare to
        Returns:
        the query
      • in

        public static DBQuery.Query in​(String field,
                                       Collection<?> values)
        Deprecated.
        The field is in the given set of values
        Parameters:
        field - The field to compare
        values - The value to compare to
        Returns:
        the query
      • notIn

        public static DBQuery.Query notIn​(String field,
                                          Object... values)
        Deprecated.
        The field is not in the given set of values
        Parameters:
        field - The field to compare
        values - The value to compare to
        Returns:
        the query
      • notIn

        public static DBQuery.Query notIn​(String field,
                                          Collection<?> values)
        Deprecated.
        The field is not in the given set of values
        Parameters:
        field - The field to compare
        values - The value to compare to
        Returns:
        the query
      • mod

        public static DBQuery.Query mod​(String field,
                                        Number mod,
                                        Number value)
        Deprecated.
        The field, modulo the given mod argument, is equal to the value
        Parameters:
        field - The field to compare
        mod - The modulo
        value - The value to compare to
        Returns:
        the query
      • all

        public static DBQuery.Query all​(String field,
                                        Collection<?> values)
        Deprecated.
        The array field contains all of the given values
        Parameters:
        field - The field to compare
        values - The values to compare to
        Returns:
        the query
      • all

        public static DBQuery.Query all​(String field,
                                        Object... values)
        Deprecated.
        The array field contains all of the given values
        Parameters:
        field - The field to compare
        values - The values to compare to
        Returns:
        the query
      • size

        public static DBQuery.Query size​(String field,
                                         int size)
        Deprecated.
        The array field is of the given size
        Parameters:
        field - The field to compare
        size - The value to compare
        Returns:
        the query
      • exists

        public static DBQuery.Query exists​(String field)
        Deprecated.
        The given field exists
        Parameters:
        field - The field to check
        Returns:
        the query
      • notExists

        public static DBQuery.Query notExists​(String field)
        Deprecated.
        The given field doesn't exist
        Parameters:
        field - The field to check
        Returns:
        the query
      • or

        public static DBQuery.Query or​(DBQuery.Query... expressions)
        Deprecated.
        One of the given expressions matches
        Parameters:
        expressions - The expressions to test
        Returns:
        the query
      • and

        public static DBQuery.Query and​(DBQuery.Query... expressions)
        Deprecated.
        All of the given expressions match
        Parameters:
        expressions - The expressions to test
        Returns:
        the query
      • nor

        public static DBQuery.Query nor​(DBQuery.Query... expressions)
        Deprecated.
        None of the given expressions match
        Parameters:
        expressions - The expressions to test
        Returns:
        the query
      • regex

        public static DBQuery.Query regex​(String field,
                                          Pattern regex)
        Deprecated.
        The given field matches the regular expression
        Parameters:
        field - The field to comare
        regex - The regular expression to match with
        Returns:
        the query
      • elemMatch

        public static DBQuery.Query elemMatch​(String field,
                                              DBQuery.Query query)
        Deprecated.
        An element in the given array field matches the given query
        Parameters:
        field - the array field
        query - The query to attempt to match against the elements of the array field
        Returns:
        the query
      • where

        public static DBQuery.Query where​(String code)
        Deprecated.
        Execute the given JavaScript code as part of the query
        Parameters:
        code - the JavaScript code
        Returns:
        the query