mongoose-selfreference
v1.0.0
Published
mongoose plugin to set up self-referential attributes
Downloads
1
Readme
mongoose-selfreference
A plugin for mongoose. It enables the creation of initially self-referential attributes. Combining this plugin with populate is not recommended.
Usage
someSchema.plugin(selfRefPlugin, options);
Options
An object with one required property, keys
, an array of
strings. Each string is the name of an attribute you want
set as a self-reference when it is undefined
.
Example
someSchema.plugin(selfRefPlugin, {
keys : ['attrOne', 'attrTwo', 'attrThree']
});
Where someSchema
is an instance of mongoose.Schema
and
attrOne, attrTwo, attrThree are the names of attributes on
the documents you want to be initially self-referential.
No changes to the mongoose.Schema
constructor invocation
are necessary to use this module, provided the type of the
self-referential attributes is the same as the type of the
document's _id
attribute (mongoose.Schema.Types.ObjectId
by default).