new MongoRepository(app, mongo, util)
Create repository
Parameters:
| Name | Type | Description |
|---|---|---|
app |
App | The application |
mongo |
Mongo | Mongo service |
util |
Util | Util service |
Members
-
<static> provides :string
-
Service name is 'repositories.mongo'
Type:
- string
-
<static> requires :Array.<string>
-
Dependencies as constructor arguments
Type:
- Array.<string>
-
<static> timeZone :string|null
-
Table time zone - mongo always uses UTC and converts to local
Type:
- string | null
Methods
-
delete(model [, mongo])
-
Delete a model
Parameters:
Name Type Argument Description modelBaseModel | number Model or ID mongoMongoClient | string <optional>
Will reuse the Mongo client provided, or if it is a string then will connect to this instance of Mongo. Returns:
Resolves to number of deleted records- Type
- Promise
-
findAll( [mongo])
-
Find all models
Parameters:
Name Type Argument Description mongoMongoClient | string <optional>
Will reuse the Mongo client provided, or if it is a string then will connect to this instance of Mongo. Returns:
Resolves to array of models- Type
- Promise
-
find(id [, mongo])
-
Find a model by ID
Parameters:
Name Type Argument Description idnumber ID to search by mongoMongoClient | string <optional>
Will reuse the Mongo client provided, or if it is a string then will connect to this instance of Mongo. Returns:
Resolves to array of models- Type
- Promise
-
save(model [, mongo])
-
Save model
Parameters:
Name Type Argument Description modelBaseModel The model mongoMongoClient | string <optional>
Will reuse the Mongo client provided, or if it is a string then will connect to this instance of Mongo. Returns:
Resolves to record ID- Type
- Promise
-
search( [options] [, mongo])
-
Search repository
Parameters:
Name Type Argument Description optionsobject <optional>
Properties
Name Type Argument Default Description collectionstring <optional>
Collection name searchobject <optional>
Search object if any sortobject <optional>
Sort object if any pageSizenumber <optional>
0 Used in limit(), 0 = all records pageNumbernumber <optional>
1 Used in skip() infoOnlyboolean <optional>
false Retrieve data rows or not mongoMongoClient | string <optional>
Will reuse the Mongo client provided, or if it is a string then will connect to this instance of Mongo. Returns:
Returns promise resolving to the following:{ totalRows: 1, // total rows in result totalPages: 1, // total number of pages pageSize: 0, // page size pageNumber: 1, // returned page number search: object, // object used to search the collection sort: object, // object used to sort the result data: [ ... ], // resulting rows as an array of models }- Type
- Promise