<abstract> new GenericMongoDBObject(linkedObjects: [, object])
Class variables are :
- {mongoose.Schema} $document
- {mongoose.Model} $model: used for db access functions
- {String} $name: flag the property which should be used to find documents by name (as in findByName() method)
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
linkedObjects: |
Array | objects to be linked to this one i.e. removed when this object is removed |
|
object |
Object |
<optional> |
to init this GenericMongoDBObject with |
- Source:
Extends
Methods
-
<protected> $convertToObjectID()
-
- Source:
-
<protected> $dbPopulateCheckReference(obj, path)
-
Check 'obj' to see if any of its paths need to be reset and return an array of path to set to null
Parameters:
Name Type Description objObject pathString - Source:
Returns:
- Type
- Array.<String>
-
<protected> $getDocumentReferenced(path)
-
Tests a path to see if it references another Document.
If so returned the model name(s) of the referenced Document(s); otherwise return nullParameters:
Name Type Description pathString - Source:
Returns:
- Type
- Object | String | null
-
<protected> $getMongoCollection()
-
Get the Mongo collection associated with this DBObject
- Source:
Returns:
- Type
- mongo.Collection
-
<protected> $updateOCC(query, update [, options] [, returnedObj])
-
Perform an Optimistic Consistency Controled update operation
Parameters:
Name Type Argument Description queryObject updateObject optionsObject <optional>
(see http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#findOneAndUpdate for complete options list)
Properties
Name Type Argument Default Description returnOriginalboolean <optional>
true When false, returns the updated document rather than the original. The default is true.
upsertboolean <optional>
false Upsert the document if it does not exist.
projectionObject <optional>
null Limits the fields to return for all matching documents.
sortObject <optional>
null Determines which document the operation modifies if the query selects multiple documents.
returnedObjany <optional>
object to wrap in the Promise if fulfilled; if null return update's value (i.e. updated document or original document depending on 'options.returnOriginal')
- Source:
Returns:
wrapping 'returnedObj' / update's result
- Type
- Promise
-
<protected> _convert(document [, options], $recursiveCall:)
-
Convert an Object into a proper DBObject
Parameters:
Name Type Argument Description documentany optionsObject <optional>
$recursiveCall:Boolean don't use
- Inherited From:
- Source:
Returns:
- Type
- DBObject
-
addToSet(property:, value, options)
-
Adds a value to an array unless the value is already present, in which case it does nothing to that array. The underlying DBObject is saved
Parameters:
Name Type Description property:String name of the array property
valueany optionsObject Properties
Name Type Argument Default Description upsertboolean <optional>
true set to false to only add 'value' to set at path 'property' if it exists (and is an Array)
eachboolean <optional>
true set to true to add all elements of 'value' separately. If set to false and 'value' is an array adds the Array
occboolean <optional>
true set to false to disable concurrency check (using Optimistic Concurrency Control) => addToSet will return a rejected Promise
- Inherited From:
- Source:
Returns:
wrapping the value which were added
- Type
- Promise
-
dbAddToSet(property:, value, options)
-
Adds a value to an array unless the value is already present, in which case it does nothing to that array. The underlying DBObject is saved
Parameters:
Name Type Description property:String name of the array property
valueany optionsObject Properties
Name Type Argument Default Description eachboolean <optional>
true set to true to add all elements of 'value' separately. If set to false and 'value' is an array adds the Array
sliceboolean <optional>
same as $slice operator in Mongo see https://docs.mongodb.com/manual/reference/operator/update/slice/
- Overrides:
- Source:
Returns:
wrapping the value which were added
- Type
- Promise
-
<protected> dbFind(query [, options])
-
Encapsulate 'this.$model.find(query)'
Parameters:
Name Type Argument Description querystring : id to lookup
optionsObject <optional>
- Overrides:
- Source:
Returns:
- Type
- Promise
-
<protected> dbFindById(id [, options])
-
Encapsulate 'this.$model.findById(id)'
Parameters:
Name Type Argument Description idstring : id to lookup
optionsObject <optional>
- Overrides:
- Source:
Returns:
- Type
- Promise
-
<protected> dbFindByIdAndRemove(id [, options])
-
Encapsulate 'this.$model.findByIdAndRemove(id)'
Parameters:
Name Type Argument Description idObject | String | Number : id to lookup, if object structure as a Query
optionsObject <optional>
- Overrides:
- Source:
Returns:
- Type
- Promise
-
<protected> dbFindOneAndUpdate(query [, options])
-
Encapsulate '$model.findByIdAndUpdate(id, query, options)'
Parameters:
Name Type Argument Description id.idstring : id to lookup
querystring optionsobject <optional>
- Overrides:
- Source:
Returns:
- Type
- Promise
-
<protected> dbPopulate( [path])
-
Replaces all document references by the actual DBObject
Parameters:
Name Type Argument Description pathArray.<String> | String | Object | Array.<Object> <optional>
path or array of path to populate; if nully populate all available references; if Object or [Object] uses Mongoose deep populate (see http://mongoosejs.com/docs/populate.html#deep-populate)
- Overrides:
- Source:
Returns:
wrapping the populated DBObject
- Type
- Promise
-
dbPush(property:, value, options)
-
Appends a specified value to an array. The underlying DBObject is saved
Parameters:
Name Type Description property:String name of the array property
valueany optionsObject Properties
Name Type Argument Default Description eachboolean <optional>
true set to true to add all elements of 'value' separately. If set to false and 'value' is an array adds the Array
- Source:
Returns:
wrapping the value which were added
- Type
- Promise
-
<protected> dbRemove( [query] [, options])
-
Encapsulate 'this.$model.remove(query)'
Parameters:
Name Type Argument Description queryObject <optional>
if empty remove the current object (this._id must then be set)
optionsObject <optional>
- Overrides:
- Source:
Returns:
- Type
- Promise
-
<protected> dbSave(options)
-
Async save of 'this'
Parameters:
Name Type Description optionsObject Properties
Name Type Argument Default Description occboolean <optional>
false set to true to force a concurrency check using Optimistic Concurrency Control
- Overrides:
- Source:
Returns:
wrapping the updated object
- Type
- Promise
-
fill(object, ignoreKeys)
-
Copy 'object' into the current 'DBObject', excluding 'ignoreKeys'
Parameters:
Name Type Description objectObject : object to clone
ignoreKeysArray.<String> : array of String containing the keys to ignore
- Inherited From:
- Source:
-
find(query, options)
-
Method to find an Object using a query
Parameters:
Name Type Description queryObject optionsObject supports lean, populateFields, limit, sort
- Inherited From:
- Source:
Returns:
wrapping an array of Objects
- Type
- Promise
-
findById(id:, options)
-
Method to find a Object based on its ID
Parameters:
Name Type Description id:String id of the object to find
optionsObject supports lean, populateFields, limit, sort
- Inherited From:
- Source:
Returns:
wrapping an Object (or null)
- Type
- Promise
-
findByName(name, options)
-
Method to find an Object based on its name
Parameters:
Name Type Description nameString optionsObject supports lean, populateFields, limit, sort
- Inherited From:
- Source:
Returns:
wrapping an array of Objects
- Type
- Promise
-
<protected> getDocument(object)
-
Generic method to create an instance of Mongoose Document (new MongooseModel()) from
this.$model. It expects 'this.$model' to have been set in the subclass's construtorParameters:
Name Type Description objectany - Source:
Returns:
- Type
- mongoose.Document
-
getName()
-
Returns the name associated with this object.
- Inherited From:
- Source:
Returns:
- Type
- String
-
isEmpty()
-
Check if the associated DBObject is empty
- Inherited From:
- Source:
Returns:
- Type
- boolean
-
lean()
-
Create a lean (and cloned) version of this object i.e. keeping the data but without the DBObject magic
Goes recursively into nested Objects- Inherited From:
- Source:
Returns:
- Type
- Object
-
populate( [path])
-
Replaces all document references by the actual DBObject
Parameters:
Name Type Argument Description pathArray | String <optional>
path or array of path to populate, is nully populate all available references
- Inherited From:
- Source:
Returns:
wrapping the populated object
- Type
- Promise
-
push(property:, value, options)
-
Appends a specified value to an array. The underlying DBObject is saved
Parameters:
Name Type Description property:String name of the array property
valueany optionsObject Properties
Name Type Argument Default Description eachboolean <optional>
true set to true to add all elements of 'value' separately. If set to false and 'value' is an array adds the Array
occboolean <optional>
true set to false to disable concurrency check (using Optimistic Concurrency Control) => push will return a rejected Promise
upsertboolean <optional>
true set to false to only add 'value' to set at path 'property' if it exists (and is an Array)
- Inherited From:
- Source:
Returns:
wrapping the updated object
- Type
- Promise
-
remove( [options])
-
Method to remove an object. This._id must be set (at least)
Since 1.3 Added an option to remove() to temporarily add nested objects to linkedObjects list
Since 1.2 remove() method is now called recursively on nested DBObject / arrays of DBObject (instead of dbRemove())Parameters:
Name Type Argument Description optionsObject <optional>
Properties
Name Type Argument Default Description deleteObject <optional>
null if null, execute a hard delete (i.e. actually remove DBObject from the DB)
Properties
Name Type Argument Description methodObject <optional>
'hard' or 'soft'
userObject <optional>
used only if options.delete.method == 'soft'
unlinkArray.<String> <optional>
additional objects to be removed (temporary add the content of the list to the object's linkedObjects' property; method == 'hard' only)
- Inherited From:
- Source:
Returns:
wrapping a fully populated removed object
- Type
- Promise
-
save( [options])
-
Method to save an Object into DB.
Since v1.2 save() don't automatically populate saved Object. Use options.populate = true if neededParameters:
Name Type Argument Description optionsObject <optional>
Properties
Name Type Argument Default Description populateboolean | String | Array.<String> <optional>
false set to populate saved object (true => populate all fields, String/String[] will be passed as argument to populate())
occboolean <optional>
false set to true to force a concurrency check using Optimistic Concurrency Control
- Inherited From:
- Source:
Returns:
wrapping the saved Object
- Type
- Promise