New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-plugin-votes

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-plugin-votes

Mongoose.js plugin to add voting methods to models.

  • 1.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

mongoose-plugin-votes

Codeship Status for CentralPing/mongoose-plugin-votes Code Climate for CentralPing/mongoose-plugin-votes Dependency Status for CentralPing/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 = require('mongoose-plugin-votes');
var schema = Schema({...});
schema.plugin(votesPlugin[, OPTIONS]);

mongoose-plugin-votes~options

Kind: inner property of mongoose-plugin-votes

ParamTypeDefaultDescription
[options]object
options.pathstring"votes"the path to create the propterty for storing votes.
options.optionsobjectproperty options to set (type will always be Array). (e.g. {select: false})
options.voteMethodNamestring"vote"the method name to set a vote.
options.unvoteMethodNamestring"unvote"the method name to unset a vote.
options.votesobject
options.votes.refstringthe reference model to use (e.g. {votes: {ref: 'ModelRefName'}})
options.votes.optionsobjectvotes 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

ParamTypeDescription
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

ParamTypeDescription
voter*If using a reference pass in the ObjectId or the document

Examples

With Strings

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']

With References

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'}]

License

Apache 2.0

Keywords

FAQs

Package last updated on 08 May 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc