Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
mongoose-plugin-votes
Advanced tools
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.
npm i --save mongoose-plugin-votes
Example
var votesPlugin = require('mongoose-plugin-votes');
var schema = Schema({...});
schema.plugin(votesPlugin[, 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}}}) |
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 |
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 |
var votesPlugin = require('mongoose-plugin-votes');
var schema = Schema({foo: String});
schema.plugin(votesPlugin);
var Foo = mongoose.model('Foo', schema);
var foo = Foo(); // foo.votes --> []
foo.vote('candy'); // foo.votes --> ['candy']
foo.vote('candy'); // foo.votes --> ['candy']
foo.vote('ice cream'); // foo.votes --> ['candy', 'ice cream']
foo.unvote('candy'); // foo.votes --> ['ice cream']
var votesPlugin = require('mongoose-plugin-votes');
var schema = Schema({foo: String});
schema.plugin(votesPlugin, {votes: {ref: 'UserModel'}});
var Foo = mongoose.model('Foo', schema);
var foo = Foo(); // foo.votes --> []
foo.vote(userA); // foo.votes --> [{_id: '507f191e810c19729de860ea'}]
foo.vote(userA.id); // foo.votes --> [{_id: '507f191e810c19729de860ea'}]
foo.vote(userB); // foo.votes --> [{_id: '507f191e810c19729de860ea'}, {_id: '507f191e810c19729de970fb'}]
foo.unvote(userA); // foo.votes --> [{_id: '507f191e810c19729de970fb'}]
Apache 2.0
FAQs
Mongoose.js plugin to add voting methods to models.
We found that mongoose-plugin-votes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.