Property | Example | Description |
$ignore | post.$ignore('content'); | Prevents validation and saving the provided property upon save. |
$isDefault | post.$isDefault('published'); | Checks whether the provided property is set to its default value. |
depopulate | post.depopulate('user'); | Takes a populated field and returns it to its unpopulated state as an objectId. |
equals | post.equals(anotherPost); | Checks whether the document contains the same data as another provided document. |
execPopulate | let promise = post.populate('user').execPopulate(); | Performs a population query as a promise. |
get | post.get('html'); | Returns the specified property from the document as a getter. |
init | post.init(mockPost, function() {}); | Initializes a document. |
inspect | post.inspect(); | Logs the contents of the document to the console. |
invalidate | post.invalidate('title', 'must not contain foobar', 'foobar'); | Marks the provided property as invalid, causing validation to fail. |
isDirectModified | post.isDirectModified('content'); | Checks whether document's provided property was directly set and modified, otherwise is false. |
isDirectSelected | post.isDirectSelected('user.email'); | Checks whether document's provided property was explicitly selected. When there is no projection, will always return true. |
isInit | post.isInit('html'); | Checks whether the provided property has been initialized. |
isModified | post.isModified('title'); | Checks whether the provided property has been modified. |
isSelected | post.isSelected('user.email'); | Checks whether the provided property was selected in the query, which initialized this document. |
markModified | post.markModified('title'); | Marks the provided property as having changes to save to the db. |
modifiedPaths | post.modifiedPaths(['title', 'content']); | Same as markModified, but takes an array of properties. |
populate | post.populate('user', function() {}); | Performs a population on the provided property in the document. |
populated | post.populated('user'); | Returns the objectId reference used for population. |
set | post.set('title', 'foobar'); | Sets the specified value to the specified property on the document as a setter. |
toJSON | post.toJSON({ getters: true }); | Same as toObject, but is called when JSON.stringify is used on the document. |
toObject | post.toObject({ getters: true }); | Converts the document into a vanilla javascript object. Can be provided options for configuring usage of virtual properties in serialization. |
toString | post.toString(); | A console.log-friendly way to serialize a document for logging. |
unmarkModified | post.unmarkModified('content'); | Clears the modified state on the specified path. |
update | post.update({ title: 'foobar' }, function(error) {}); | Sends an update command with this document's ID as the query selector. |
validate | post.validate(function(error) {} ); | Executes registered validation rules for this document. |
validateSync | let error = post.validateSync(); | Synchronous version of validate. |
errors | post.errors(); | Returns all the current validation errors on this document. |
id | post.id(); | Returns this document's ID as a string. |
isNew | post.isNew(); | Check whether the document is new. |
schema | post.schema(); | Returns a reference to the document's schema. |
If you are interested in learning more about working with documents, and document relationships, you can check out the official Mongoose documentation page: