const mixinafMorphia::Queries

afMorphia::Queries

Convenience shortcut methods for creating Query objects. These values mimic those on QueryCriterion.

const class MyQueries : Queries {

    Query price() {
        return and([
            or([ eq("price", 0.99f), eq("price", 1.99f)  ]),
            or([ eq("sale", true),   lessThan("qty", 29) ])
        ])
    }
and

Source

Query and(Query q1, Query q2, Query? q3 := null, Query? q4 := null)

Selects documents that pass all the query expressions in the given list. Example:

query := and(
  lessThan("quantity", 20),
  eq("price", 10)
)

Note the above could also be written as:

lessThan("quantity", 20).and([eq("price", 10)])

@see http://docs.mongodb.org/manual/reference/operator/query/and/

contains

Source

Query contains(Str fieldName, Str value, Bool caseInsensitive := true)

Matches string values that contain the given value.

Note that matching is performed with regular expressions.

endsWith

Source

Query endsWith(Str fieldName, Str value, Bool caseInsensitive := true)

Matches string values that end with the given value.

Note that matching is performed with regular expressions.

eq

Source

Query eq(Str fieldName, Obj? value)

Matches values that are equal to the given object.

eqIgnoreCase

Source

Query eqIgnoreCase(Str fieldName, Str value)

Matches string values that equal (ignoring case) the given value.

Note that matching is performed with regular expressions.

exists

Source

Query exists(Str fieldName, Bool exists := true)

Matches if the field exists (or not), even if it is null.

@see http://docs.mongodb.org/manual/reference/operator/query/exists/

greaterThan

Source

Query greaterThan(Str fieldName, Obj value)

Matches values that are greater than the given object.

@see http://docs.mongodb.org/manual/reference/operator/query/gt/

greaterThanOrEqTo

Source

Query greaterThanOrEqTo(Str fieldName, Obj value)

Matches values that are greater than or equal to the given object.

@see http://docs.mongodb.org/manual/reference/operator/query/gte/

in

Source

Query in(Str fieldName, Obj[] values)

Matches values that equal any one of the given values.

@see http://docs.mongodb.org/manual/reference/operator/query/in/

lessThan

Source

Query lessThan(Str fieldName, Obj value)

Matches values that are less than the given object.

@see http://docs.mongodb.org/manual/reference/operator/query/gt/

lessThanOrEqTo

Source

Query lessThanOrEqTo(Str fieldName, Obj value)

Matches values that are less than or equal to the given object.

@see http://docs.mongodb.org/manual/reference/operator/query/lte/

makeInstance

Source

static new makeInstance()

Returns an instance of Queries. Use when you'd rather not inherit from Queries.

Query price() {
    q := Queries()
    return q.or([
        q.eq("price", 0.99f), 
        q.eq("price", 1.99f)
    ])
}
matchesRegex

Source

Query matchesRegex(Str fieldName, Regex regex)

Matches string values that equal the given regular expression.

mod

Source

Query mod(Str fieldName, Int divisor, Int remainder)

Matches values based on their remainder after a division (modulo operation).

@see http://docs.mongodb.org/manual/reference/operator/query/mod/

nor

Source

Query nor(Query q1, Query q2, Query? q3 := null, Query? q4 := null)

Selects documents that fail all the query expressions in the given list. Example:

query := nor(
  lessThan("quantity", 20),
  eq("price", 10)
)

@see http://docs.mongodb.org/manual/reference/operator/query/nor/

not

Source

QueryCriterion not(QueryCriterion query)

Selects documents that do not match the given following criterion. Example:

not(Query.field("price")).lessThan(10)

Note this also matches documents that do not contain the field.

@see http://docs.mongodb.org/manual/reference/operator/query/not/

notEq

Source

Query notEq(Str fieldName, Obj? value)

Matches values that are not equal to the given object.

Note this also matches documents that do not contain the field.

@see http://docs.mongodb.org/manual/reference/operator/query/ne/

notIn

Source

Query notIn(Str fieldName, Obj[] values)

Matches values that do not equal any one of the given values.

Note this also matches documents that do not contain the field.

@see http://docs.mongodb.org/manual/reference/operator/query/nin/

or

Source

Query or(Query q1, Query q2, Query? q3 := null, Query? q4 := null)

Selects documents that pass any of the query expressions in the given list. Example:

query := or(
  lessThan("quantity", 20),
  eq("price", 10)
)

@see http://docs.mongodb.org/manual/reference/operator/query/or/

startsWith

Source

Query startsWith(Str fieldName, Str value, Bool caseInsensitive := true)

Matches string values that start with the given value.

Note that matching is performed with regular expressions.