Spring Data MongoDB - Core

org.springframework.data.mongodb.core.query
Class Criteria

java.lang.Object
  extended by org.springframework.data.mongodb.core.query.Criteria
All Implemented Interfaces:
CriteriaDefinition
Direct Known Subclasses:
GridFsCriteria

public class Criteria
extends Object
implements CriteriaDefinition

Central class for creating queries. It follows a fluent API style so that you can easily chain together multiple criteria. Static import of the 'Criteria.where' method will improve readability.

Author:
Thomas Risberg, Oliver Gierke, Thomas Darimont, Christoph Strobl

Constructor Summary
  Criteria()
           
protected Criteria(List<Criteria> criteriaChain, String key)
           
  Criteria(String key)
           
 
Method Summary
 Criteria all(Collection<?> o)
          Creates a criterion using the $all operator.
 Criteria all(Object... o)
          Creates a criterion using the $all operator.
 Criteria and(String key)
          Static factory method to create a Criteria using the provided key
 Criteria andOperator(Criteria... criteria)
          Creates an 'and' criteria using the $and operator for all of the provided criteria.
 Criteria elemMatch(Criteria c)
          Creates a criterion using the $elemMatch operator
 boolean equals(Object obj)
           
 Criteria exists(boolean b)
          Creates a criterion using the $exists operator.
 com.mongodb.DBObject getCriteriaObject()
           
 String getKey()
           
protected  com.mongodb.DBObject getSingleCriteriaObject()
           
 Criteria gt(Object o)
          Creates a criterion using the $gt operator.
 Criteria gte(Object o)
          Creates a criterion using the $gte operator.
 int hashCode()
           
 Criteria in(Collection<?> c)
          Creates a criterion using the $in operator.
 Criteria in(Object... o)
          Creates a criterion using the $in operator.
 Criteria is(Object o)
          Creates a criterion using equality
 Criteria lt(Object o)
          Creates a criterion using the $lt operator.
 Criteria lte(Object o)
          Creates a criterion using the $lte operator.
 Criteria maxDistance(double maxDistance)
          Creates a geospatical criterion using a $maxDistance operation, for use with $near
 Criteria mod(Number value, Number remainder)
          Creates a criterion using the $mod operator.
 Criteria ne(Object o)
          Creates a criterion using the $ne operator.
 Criteria near(org.springframework.data.geo.Point point)
          Creates a geospatial criterion using a $near operation.
 Criteria nearSphere(org.springframework.data.geo.Point point)
          Creates a geospatial criterion using a $nearSphere operation.
 Criteria nin(Collection<?> o)
          Creates a criterion using the $nin operator.
 Criteria nin(Object... o)
          Creates a criterion using the $nin operator.
 Criteria norOperator(Criteria... criteria)
          Creates a 'nor' criteria using the $nor operator for all of the provided criteria.
 Criteria not()
          Creates a criterion using the $not meta operator which affects the clause directly following
 Criteria orOperator(Criteria... criteria)
          Creates an 'or' criteria using the $or operator for all of the provided criteria Note that mongodb doesn't support an $or operator to be wrapped in a $not operator.
 Criteria regex(Pattern pattern)
          Syntactical sugar for is(Object) making obvious that we create a regex predicate.
 Criteria regex(String re)
          Creates a criterion using a $regex operator.
 Criteria regex(String re, String options)
          Creates a criterion using a $regex and $options operator.
 Criteria size(int s)
          Creates a criterion using the $size operator.
 Criteria type(int t)
          Creates a criterion using the $type operator.
static Criteria where(String key)
          Static factory method to create a Criteria using the provided key
 Criteria within(org.springframework.data.geo.Shape shape)
          Creates a geospatial criterion using a $within operation.
 Criteria withinSphere(org.springframework.data.geo.Circle circle)
          Creates a geospatial criterion using a $within $centerSphere operation.
 Criteria withinSphere(Circle circle)
          Deprecated. As of 1.5, Use withinSphere(Circle). This method is scheduled to be removed in the next major release.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Criteria

public Criteria()

Criteria

public Criteria(String key)

Criteria

protected Criteria(List<Criteria> criteriaChain,
                   String key)
Method Detail

where

public static Criteria where(String key)
Static factory method to create a Criteria using the provided key

Parameters:
key -
Returns:

and

public Criteria and(String key)
Static factory method to create a Criteria using the provided key

Returns:

is

public Criteria is(Object o)
Creates a criterion using equality

Parameters:
o -
Returns:

ne

public Criteria ne(Object o)
Creates a criterion using the $ne operator.

Parameters:
o -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/ne/

lt

public Criteria lt(Object o)
Creates a criterion using the $lt operator.

Parameters:
o -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/lt/

lte

public Criteria lte(Object o)
Creates a criterion using the $lte operator.

Parameters:
o -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/lte/

gt

public Criteria gt(Object o)
Creates a criterion using the $gt operator.

Parameters:
o -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/gt/

gte

public Criteria gte(Object o)
Creates a criterion using the $gte operator.

Parameters:
o -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/gte/

in

public Criteria in(Object... o)
Creates a criterion using the $in operator.

Parameters:
o - the values to match against
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/in/

in

public Criteria in(Collection<?> c)
Creates a criterion using the $in operator.

Parameters:
c - the collection containing the values to match against
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/in/

nin

public Criteria nin(Object... o)
Creates a criterion using the $nin operator.

Parameters:
o -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/nin/

nin

public Criteria nin(Collection<?> o)
Creates a criterion using the $nin operator.

Parameters:
o -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/nin/

mod

public Criteria mod(Number value,
                    Number remainder)
Creates a criterion using the $mod operator.

Parameters:
value -
remainder -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/mod/

all

public Criteria all(Object... o)
Creates a criterion using the $all operator.

Parameters:
o -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/all/

all

public Criteria all(Collection<?> o)
Creates a criterion using the $all operator.

Parameters:
o -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/all/

size

public Criteria size(int s)
Creates a criterion using the $size operator.

Parameters:
s -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/size/

exists

public Criteria exists(boolean b)
Creates a criterion using the $exists operator.

Parameters:
b -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/exists/

type

public Criteria type(int t)
Creates a criterion using the $type operator.

Parameters:
t -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/type/

not

public Criteria not()
Creates a criterion using the $not meta operator which affects the clause directly following

Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/not/

regex

public Criteria regex(String re)
Creates a criterion using a $regex operator.

Parameters:
re -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/regex/

regex

public Criteria regex(String re,
                      String options)
Creates a criterion using a $regex and $options operator.

Parameters:
re -
options -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/regex/, http://docs.mongodb.org/manual/reference/operator/query/regex/#op._S_options

regex

public Criteria regex(Pattern pattern)
Syntactical sugar for is(Object) making obvious that we create a regex predicate.

Parameters:
pattern -
Returns:

withinSphere

public Criteria withinSphere(org.springframework.data.geo.Circle circle)
Creates a geospatial criterion using a $within $centerSphere operation. This is only available for Mongo 1.7 and higher.

Parameters:
circle - must not be null
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/geoWithin/, http://docs.mongodb.org/manual/reference/operator/query/centerSphere/

withinSphere

@Deprecated
public Criteria withinSphere(Circle circle)
Deprecated. As of 1.5, Use withinSphere(Circle). This method is scheduled to be removed in the next major release.

Parameters:
circle -
Returns:
See Also:
withinSphere(Circle)

within

public Criteria within(org.springframework.data.geo.Shape shape)
Creates a geospatial criterion using a $within operation.

Parameters:
shape -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/geoWithin/

near

public Criteria near(org.springframework.data.geo.Point point)
Creates a geospatial criterion using a $near operation.

Parameters:
point - must not be null
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/near/

nearSphere

public Criteria nearSphere(org.springframework.data.geo.Point point)
Creates a geospatial criterion using a $nearSphere operation. This is only available for Mongo 1.7 and higher.

Parameters:
point - must not be null
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/nearSphere/

maxDistance

public Criteria maxDistance(double maxDistance)
Creates a geospatical criterion using a $maxDistance operation, for use with $near

Parameters:
maxDistance -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/maxDistance/

elemMatch

public Criteria elemMatch(Criteria c)
Creates a criterion using the $elemMatch operator

Parameters:
c -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/query/elemMatch/

orOperator

public Criteria orOperator(Criteria... criteria)
Creates an 'or' criteria using the $or operator for all of the provided criteria

Note that mongodb doesn't support an $or operator to be wrapped in a $not operator.

Parameters:
criteria -
Throws:
IllegalArgumentException - if orOperator(Criteria...) follows a not() call directly.

norOperator

public Criteria norOperator(Criteria... criteria)
Creates a 'nor' criteria using the $nor operator for all of the provided criteria.

Note that mongodb doesn't support an $nor operator to be wrapped in a $not operator.

Parameters:
criteria -
Throws:
IllegalArgumentException - if norOperator(Criteria...) follows a not() call directly.

andOperator

public Criteria andOperator(Criteria... criteria)
Creates an 'and' criteria using the $and operator for all of the provided criteria.

Note that mongodb doesn't support an $and operator to be wrapped in a $not operator.

Parameters:
criteria -
Throws:
IllegalArgumentException - if andOperator(Criteria...) follows a not() call directly.

getKey

public String getKey()

getCriteriaObject

public com.mongodb.DBObject getCriteriaObject()
Specified by:
getCriteriaObject in interface CriteriaDefinition

getSingleCriteriaObject

protected com.mongodb.DBObject getSingleCriteriaObject()

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

Spring Data MongoDB - Core

Copyright © 2011-2014-2014 Pivotal Software, Inc.. All Rights Reserved.