mongoose-plugin-votes
A mongoose.js plugin that provides vote
and unvote
methods for model instances. The method names are configurable (e.g. like
and unlike
).
Note: document changes are not persisted until document is saved.
Installation
npm i --save mongoose-plugin-votes
API Reference
Example
var votesPlugin = ;var schema = ;schema;
mongoose-plugin-votes~options
Kind: inner property of mongoose-plugin-votes
Param | Type | Default | Description |
---|---|---|---|
[options] | object |
||
options.path | string |
"votes" |
the path to create the propterty for storing votes. |
options.options | object |
property options to set (type will always be Array ). (e.g. {select: false}) |
|
options.voteMethodName | string |
"vote" |
the method name to set a vote. |
options.unvoteMethodName | string |
"unvote" |
the method name to unset a vote. |
options.votes | object |
||
options.votes.ref | string |
the reference model to use (e.g. {votes: {ref: 'ModelRefName'}}) |
|
options.votes.options | object |
votes property options to set (type will always be String ). (e.g. {votes: {options: {select: false}}}) |
mongoose-plugin-votes~vote(voter)
The vote
method appends the passed in value to the votes
path array
Kind: inner method of mongoose-plugin-votes
Param | Type | Description |
---|---|---|
voter | * |
If using a reference pass in the ObjectId or the document |
mongoose-plugin-votes~unvote(voter)
The unvote
method removes the passed in value from the votes
path array
Kind: inner method of mongoose-plugin-votes
Param | Type | Description |
---|---|---|
voter | * |
If using a reference pass in the ObjectId or the document |
Examples
With Strings
var votesPlugin = ;var schema = ;schema; var Foo = mongoose;var foo = ; // foo.votes --> []foo; // foo.votes --> ['candy']foo; // foo.votes --> ['candy']foo; // foo.votes --> ['candy', 'ice cream']foo; // foo.votes --> ['ice cream']
With References
var votesPlugin = ;var schema = ;schema; var Foo = mongoose;var foo = ; // foo.votes --> []foo; // foo.votes --> [{_id: '507f191e810c19729de860ea'}]foo; // foo.votes --> [{_id: '507f191e810c19729de860ea'}]foo; // foo.votes --> [{_id: '507f191e810c19729de860ea'}, {_id: '507f191e810c19729de970fb'}]foo; // foo.votes --> [{_id: '507f191e810c19729de970fb'}]
License
Apache 2.0