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(Obj name, Str value, Bool caseInsensitive := true)

Matches string values that contain the given value.

Note that matching is performed with regular expressions.

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

endsWith

Source

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

Matches string values that end with the given value.

Note that matching is performed with regular expressions.

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

eq

Source

Query eq(Obj name, Obj? value)

Matches values that are equal to the given object.

name may either a MongoDB property name (Str) or a field annotated with @Property.

eqIgnoreCase

Source

Query eqIgnoreCase(Obj name, Str value)

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

Note that matching is performed with regular expressions.

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

exists

Source

Query exists(Obj name, Bool exists := true)

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

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

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

greaterThan

Source

Query greaterThan(Obj name, Obj value)

Matches values that are greater than the given object.

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

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

greaterThanOrEqTo

Source

Query greaterThanOrEqTo(Obj name, Obj value)

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

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

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

in

Source

Query in(Obj name, Obj[] values)

Matches values that equal any one of the given values.

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

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

lessThan

Source

Query lessThan(Obj name, Obj value)

Matches values that are less than the given object.

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

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

lessThanOrEqTo

Source

Query lessThanOrEqTo(Obj name, Obj value)

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

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

@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(Obj name, Regex regex)

Matches string values that equal the given regular expression.

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

mod

Source

Query mod(Obj name, Int divisor, Int remainder)

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

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

@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(Obj name, Obj? value)

Matches values that are not equal to the given object.

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

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

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

notIn

Source

Query notIn(Obj name, 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.

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

@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(Obj name, Str value, Bool caseInsensitive := true)

Matches string values that start with the given value.

Note that matching is performed with regular expressions.

name may either an entity Field annotated with @Property or a MongoDB property name (Str).

textSearch

Source

Query textSearch(Str search, [Str:Obj?]? options := null)

Performs a text search on the collection.

Text searching makes use of stemming and ignores language stop words. Quotes may be used to search for exact phrases and prefixing a word with a hyphen-minus (-) negates it.

Results are automatically ordered by search relevance.

To use text searching, make sure the Collection has a text Index else MongoDB will throw an Err.

options may include the following:

Name

Type

Desc

$language

Bool

Determines the list of stop words for the search and the rules for the stemmer and tokenizer. See Supported Text Search Languages. Specify none for simple tokenization with no stop words and no stemming. Defaults to the language of the index.

$caseSensitive

Bool

Enable or disable case sensitive searching. Defaults to false.

$diacriticSensitive

Int

Enable or disable diacritic sensitive searching. Defaults to false.

@see https://docs.mongodb.com/manual/reference/operator/query/text/.