classafMorphia::Query

sys::Obj
  afMorphia::Query

A means to build Mongo queries with sane objects and methods. (And not some incomprehensible mess of nested maps and lists!)

Pass Query objects to a QueryExecutor to run them.

and

Source

Query and(Query[] criteria)

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

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

Note the above could also be written implicitly with:

Query().field("quantity").lessThan(20).field("price").eq(10)

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

field

Source

QueryCriterion field(Obj name)

Creates a match for the given field name. It may reference nested objects using dot notation. Example, user.name

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

nor

Source

Query nor(Query[] criteria)

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

Query().nor([
  Query().field("quantity").lessThan(20),
  Query().field("price").eq(10)
])

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

or

Source

Query or(Query[] criteria)

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

Query().or([
  Query().field("quantity").lessThan(20),
  Query().field("price").eq(10)
])

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

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/.

toMongo

Source

Str:Obj toMongo(Datastore datastore)

Returns a Mongo document representing the query. May be used by Datastore and Collection methods such as findAndUpdate(...).

toStr

Source

virtual override Str toStr()

Pretty prints a basic representation of the query.

Note that entity values are not converted to their Mongo equivalents.

where

Source

Query where(Code where)

Selects documents based on the return value of a javascript function. Example:

Query().where(Code("this.name == 'Judge Dredd'"))

As only 1 where function is allowed per query, only the last where function is used.

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