This method performs an aggregate query and returns a mongo
aggregate result which consists of a collection of the provided
model's items.
This method also executes the search query using the Mongo service
connected to handle {@param model}.
This method executes a count query using the {@link model}
argument.
Caution: Count queries require a considerable amount of RAM
to execute. It is preferred to use pro-active statistics with
collections that contain one document with a counter.
The number of matching documents.
This method updates exactly one document in a collection. The
query is build using getQueryConfig and can thereby use
any columns of the document.
The query configuration with sort
, order
, pageNumber
, pageSize
.
The model class instance used for the resulting document.
The fields or data that has to be updated (will be added to $set: {}
).
The operations that must be run additionally (e.g. $inc: {}
) (optional).
Method to query the existence of a document in the
collection mapped to {@link TModel}.
This executes a lean mongoose query such that the
properties of the returned document are reduced to
only the "_id"
field.
The query configuration with sort
, order
, pageNumber
, pageSize
.
The model class instance used for matching documents.
Whether a document exists which validates the passed query.
Create a generic search query that is compatible with Mongo. The
returned {@link PaginatedResultDto} contains a data
field and a
pagination
field to permit multiple queries to be sequenced.
This method also executes the search query using the Mongo service
connected to handle {@param model}.
The query configuration with sort
, order
, pageNumber
, pageSize
.
The model class instance used for resulting documents.
The matching documents after execution of the query.
Find one TDocument
instance in the database and use
a query based on the Queryable class.
The query configuration with sort
, order
, pageNumber
, pageSize
.
The model class instance used for the resulting document.
Determines whether the query should be lean (strip out document properties).
The resulting document.
Create a generic search query that is compatible with Mongo. The
returned {@link PaginatedResultDto} contains a data
field and a
pagination
field to permit multiple queries to be sequenced.
This method also executes the search query using the Mongo service
connected to handle {@param model}.
The query configuration with sort
, order
, pageNumber
, pageSize
.
The model class instance used for resulting documents.
The matching documents after execution of the query.
Format the search query parameters to a Mongo compatible
aggregate search query. The resulting object can be used
to configure an executable Mongo aggregation or query.
Note that pagination parameters can be omitted with the
following defaults being used: sort="_id"
, order="asc"
,
pageNumber=1
, pageSize=20
.
Note that this method takes three generics that must
extend the Documentable class and must also
contain a collectionName
, e.g. in Account. Only
the first of these generics is obligatory, others can
be used when handling more complex union queries.
The query configuration with sort
, order
, pageNumber
, pageSize
.
(Optional) This parameter should contain a map of Queryable objects - defaults to empty union specification (no union).
(Optional) This parameter should contain one or more $count
pipeline stage(s) - defaults to empty metadata.
The resulting aggregate search query specification that is compatible with Mongo aggregate queries.
Format the search query parameters to a Mongo compatible
documents search query. The resulting object can be used
to configure an executable Mongo aggregation or query.
Note that pagination parameters can be omitted with the
following defaults being used: sort="_id"
, order="asc"
,
pageNumber=1
, pageSize=20
.
Note that the generic TQueryDocument
should usually be
an object that extends Documentable, this is the
case for example with AccountDocument and it will
also contain a collectionName
as defined in Account.
The query configuration with sort
, order
, pageNumber
, pageSize
.
The configured SearchQuery with pagination parameters and sanitized Mongo query.
This method sanitizes a search query and returns a mongo
compatible query that can be executed and uses the correct
types for its conditions (and field values).
This method can be used whenever data has been read from
Mongo and still has string typed values. Note that this
routine is not compatible with deep objects and may corrupt
typings of complex class instances.
An object that contains unsafe (non-sanitized) query conditions.
The sanitized search query, can be passed in mongoose $match
.
This method type-casts individual query values to primitive
types and creates routines for specific primitives like number
or array
.
Following rules apply:
{ $in: [+value, value] }
// both string and numeric values.A field value that needs to be type-casted to a primitive or using a routine.
A type-cast representation of the passed value or a Mongo routine configuration.
Create a generic union search query that is compatible with Mongo. The
returned {@link PaginatedResultDto} contains a data
field and a
pagination
field to permit multiple queries to be sequenced.
This method also executes the search query using the Mongo service
connected to handle {@param model}.
This method is different find in that it permits to execute a
union query, effectively combining multiple collections in the
result set.
Note that this method takes three generics that must
extend the Documentable class and must also
contain a collectionName
, e.g. in Account. Only
the first of these generics is obligatory, others can
be used when handling more complex union queries and by default
may be omitted.
The query configuration with sort
, order
, pageNumber
, pageSize
.
The model class instance used for the resulting document.
(Optional) This parameter should contain a map of Queryable objects - defaults to empty union specification (no union).
(Optional) This parameter should contain one or more $count
pipeline stage(s) - defaults to empty metadata.
The resulting aggregate search query specification that is compatible with Mongo aggregate queries.
Method to update a batch of documents in one collection. The
query built here uses a document's _id
field value and
updates all fields present in the TDocument
generic class.
Note that the Documentable concern is used as a
requirement of TDocument
to make sure that the _id
field
is indeed present and populated.
Note also that this method automatically sets the value of
a field updatedAt
to the time of execution of the query.
The model class instance used for the resulting document.
The list of matching documents that must be updated with this batch operation.
The number of documents affected by the update queries.
Generated using TypeDoc
Abstraction layer for queries setup using the Mongo service. This class contains methods to validate, process and format database queries.
.
Native field values will be casted to their Typescript equivalent depending on the field value in Mongo, i.e.
"true"
becomestrue
.Also, arrays are always passed to the
$in
routine, currently no other operations are possible with array and objects.Note that you must pass a document class to the generic
TDocument
template of this class, e.g. QueryServiceInject and use the QueryService in another class
add handler abstraction logic
Method
typecastField
does not permit simple arithmetical operations like<><==>
on numbers.Method
typecastField
is most likely incompatible with complex class objects, must be handled.Method
typecastField
mixes functionalities by defining the$in
routines as a type-cast result.v0.1.0