<abstract> new DBObject(linkedObjects: [, object])
Subclasses should set the following property in the constructor:
- '$name' (string): it will be used to lookup the property which will be used as the "name" of the objects (e.g., in findByName())
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 DBObject with |
- Source:
Members
-
<static, constant> OCC_MAX_RETRIES
-
- Source:
-
<static, constant> STATUS
-
- Source:
Methods
-
<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
- 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
- Source:
Throws:
ConcurrencyDBErrorReturns:
wrapping the value which were added
- Type
- Promise
-
<protected> dbAddToSet()
-
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
Subclasses must override this method- Source:
Returns:
- Type
- Promise
-
<protected> dbFind(query [, options])
-
Find object matching 'query'
Subclasses must override this methodParameters:
Name Type Argument Description queryobject optionsObject <optional>
- Source:
Returns:
- Type
- Promise
-
<protected> dbFindById(id [, options])
-
Find object which id is "id"
Subclasses must override this methodParameters:
Name Type Argument Description idobject optionsObject <optional>
- Source:
Returns:
- Type
- Promise
-
<protected> dbFindByIdAndRemove(id [, options])
-
Finds a matching document, removes it, returning the found document (if any)
Subclasses must override this methodParameters:
Name Type Argument Description idObject | Number | String optionsObject <optional>
- Source:
Returns:
- Type
- Promise
-
<protected> dbFindOneAndUpdate(query [, options])
-
Find object with id 'id' and update its values based on 'query'.
Subclasses must override this methodParameters:
Name Type Argument Description id.idstring : id to lookup
querystring optionsobject <optional>
- Source:
Returns:
- Type
- Promise
-
<protected> dbPopulate( [path])
-
Replaces all document references by the actual DBObject
Subclasses must override this methodParameters:
Name Type Argument Description pathArray | String <optional>
path or array of path to populate, is nully populate all available references
- Source:
Returns:
- Type
- Promise
-
<protected> dbRemove(query [, options])
-
Remove object matching 'query'
Subclasses must override this methodParameters:
Name Type Argument Description queryObject optionsObject <optional>
- Source:
Returns:
- Type
- Promise
-
<protected> dbSave()
-
Save object
Subclasses must override this method- Source:
Returns:
- 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
- Source:
-
find(query, options)
-
Method to find an Object using a query
Parameters:
Name Type Description queryObject optionsObject supports lean, populateFields, limit, sort
- 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
- 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
- Source:
Returns:
wrapping an array of Objects
- Type
- Promise
-
getName()
-
Returns the name associated with this object.
- Source:
Returns:
- Type
- String
-
isEmpty()
-
Check if the associated DBObject is empty
- 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- 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
- 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)
- Source:
Throws:
ConcurrencyDBErrorReturns:
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)
- 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
- Source:
Returns:
wrapping the saved Object
- Type
- Promise