Empty object that you can use for storing properties on the document. This is handy for passing data to middleware without conflicting with Mongoose internals.
A string containing the current operation that Mongoose is executing
on this document. Can be null
, 'save'
, 'validate'
, or 'remove'
.
Set this property to add additional query filters when Mongoose saves this document and isNew
is false.
This documents __v.
This documents _id.
If this is a discriminator model, baseModelName
is the name of the base model.
Collection the model uses.
Connection the model uses.
Returns the current validation errors.
The string version of this documents _id.
Boolean flag specifying if the document is new.
The document's schema.
This method must return an object that can be used as the value
for the mongodb find
operations. Typically, this method returns
an object where keys are primary key(s) of the entity and values
are those of the document represented by the current instance.
If not overloaded in child classes, we use the default auto-generated
id
column as it is always present with mongodb.
The individual document data that is used in a query.
Assert that a given path or paths is populated. Throws an error if not populated.
Returns an array of all populated documents associated with the query
Don't run validation on this path or persist changes to this path.
Increments the numeric value at path
by the given val
.
When you call save()
on this document, Mongoose will send a
$inc
as opposed to a $set
.
Checks if a path is set to its default.
Getter/setter, determines whether the document was removed or not.
Returns true if the given path is nullish or only contains empty objects. Useful for determining whether this subdoc will get stripped out by the minimize option.
Checks if a path is invalid
Marks a path as valid, removing existing validation errors.
Returns the model with the given name on this document's associated connection.
If this document is a subdocument or populated document, returns the document's parent. Returns undefined otherwise.
Getter/setter around the session associated with this document. Used to
automatically set session
if you save()
a doc that you got from a
query with an associated session.
Alias for set()
, used internally to avoid conflicts
Removes this document from the db.
Removes this document from the db.
Takes a populated field and returns it to its unpopulated state. If called with no arguments, then all populated fields are returned to their unpopulated state.
Returns the list of paths that have been directly modified. A direct
modified path is a path that you explicitly set, whether via doc.foo = 'bar'
,
Object.assign(doc, { foo: 'bar' })
, or doc.set('foo', 'bar')
.
Returns true if this document is equal to another document.
Documents are considered equal when they have matching _id
s, unless neither
document has an _id
, in which case this function falls back to using
deepEqual()
.
Returns the value of a path.
Returns the changes that happened to the document in the format that will be sent to MongoDB.
Signal that we desire an increment of this documents version.
Initializes the document without setters or marking anything modified. Called internally after a document is returned from mongodb. Normally, you do not need to call this function on your own.
Marks a path as invalid, causing validation to fail.
Returns true if path
was directly set and modified, else false.
Checks if path
was explicitly selected. If no projection, always returns true.
Checks if path
is in the init
state, that is, it was set by Document#init()
and not modified since.
Returns true if any of the given paths are modified, else false. If no arguments, returns true
if any path
in this document is modified.
Checks if path
was selected in the source query which initialized this document.
Marks the path as having pending changes to write to the db.
Returns the list of paths that have been modified.
Overwrite all values in this document with the values of obj
, except
for immutable properties. Behaves similarly to set()
, except for it
unsets all properties that aren't in obj
.
Populates document references.
Gets _id(s) used during population of the given path
. If the path was not populated, returns undefined
.
Removes this document from the db.
Sends a replaceOne command with this document _id
as the query selector.
Saves this document by inserting a new document into the database if document.isNew is true
, or sends an updateOne operation with just the modified paths if isNew
is false
.
Sets the value of a path, or many paths.
The return value of this method is used in calls to JSON.stringify(doc).
Converts this document into a plain-old JavaScript object (POJO).
Clears the modified state on the specified path.
Sends an update command with this document _id
as the query selector.
Sends an updateOne command with this document _id
as the query selector.
Executes registered validation rules for this document.
Executes registered validation rules (skipping asynchronous validators) for this document.
Generated using TypeDoc
COMMON
Documentable
This concern requires the presence of fields that consist in delivering documentable information. This type of information is persisted in MongoDB collection documents.
e.g. alongside StateSchema, we define StateDocument which is a mixin that comprises of State and this
Documentable
class.v0.2.0