# mongoose-voting

> Mongoose plugin to upvote/downvote stuff. Extends any model with handy methods for voting.

Latest version **0.3.0** (published 2015-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongoose-voting
pnpm add mongoose-voting
yarn add mongoose-voting
bun add mongoose-voting
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2015-12-17 |
| First published | 2013-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 46 |
| Author | Cristian Douce |
| Maintainers | cristiandouce |
| Keywords | vote, voting, mongoose, upvote, downvote, census |

## Links

- npm: https://www.npmjs.com/package/mongoose-voting
- Repository: https://github.com/cristiandouce/mongoose-voting
- Homepage: https://github.com/cristiandouce/mongoose-voting#readme
- Issues: https://github.com/cristiandouce/mongoose-voting/issues
- npm.io page: https://npm.io/package/mongoose-voting

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2015-12-17
- 0.2.0 — 2014-07-10
- 0.1.1 — 2013-06-14
- 0.1.0 — 2013-06-14

## README

# mongoose-voting

  Mongoose plugin to upvote/downvote stuff. Extends any model with handy methods for voting.

  [![Build Status](https://travis-ci.org/cristiandouce/mongoose-voting.png?branch=master)](https://travis-ci.org/cristiandouce/mongoose-voting)

## Install

```
  $ npm install mongoose-voting
```

## Usage example

```js
  var CommentSchema = new Schema({..});

  // Default voter is `User` model
  CommentSchema.plugin(voting);

  // Or you can tell `mongoose-voting`
  // which model references
  CommentSchema.plugin(voting, { ref: 'Author' });

  // ...

  var author = new Author({});
  var comment = new Comment({});

  // upvote and check
  comment.upvote(author);
  comment.upvoted(author);      // true
  comment.downvoted(author);    // false

  // downvote with save
  comment.downvote(author, function(err, doc) {
    assert.equal(doc, comment);  // true
    doc.downvoted(author);      // true
  });

  comment.voted(author);        // true
```

## API

### .upvote(user)
  Upvotes document by user. `user` can be either a model instance (like `User`), an `ObjectId` or even the hex string from `ObjectId`.
```js
  comment.upvote(author);
  comment.voted(author);    // true
  comment.upvoted(author);  // true
```

### .upvote(user, fn)
  Same as `.upvote(user)` but calls `save` on model with `fn` function as callback.
```js
  comment.upvote(author, function(err, doc) {
    doc.voted(author);    // true
    doc.upvoted(author);  // true
  });
```

### .downvote(user)
  Downvotes document by user. `user` can be either a model instance (like `User`), an `ObjectId` or even the hex string from `ObjectId`.
```js
  comment.upvote(author);
  comment.voted(author);    // true
  comment.upvoted(author);  // true
```

### .downvote(user, fn)
  Same as `.downvote(user)` but calls `save` on model with `fn` function as callback.
```js
  comment.downvote(author, function(err, doc) {
    doc.voted(author);      // true
    doc.downvoted(author);  // true
  });
```

### .unvote(user)
  Cancels any vote cast by user. `user` can be either a model instance (like `User`), an `ObjectId` or even the hex string from `ObjectId`.
```js
  comment.upvote(author);
  comment.voted(author);    // true
  comment.unvote(author);
  comment.voted(author);    // false
```

### .unvote(user, fn)
  Same as `.unvote(user)` but calls `save` on model with `fn` function as callback.
```js
  comment.upvote(author);
  comment.voted(author);    // true
  comment.unvote(author);
  comment.voted(author);    // false
```

### .upvoted(user)
  Returns `true` if document was 'upvoted' by user. `false` otherwise.
```js
  comment.upvote(user);
  comment.upvoted(user);    // true
  comment.downvoted(user);  // false
```

### .downvoted(user)
  Returns `true` if document was 'downvoted' by user. `false` otherwise.
```js
  comment.downvote(user);
  comment.upvoted(user);    // false
  comment.downvoted(user);  // true
```

### .voted(user)
  Returns `true` if document was 'upvoted' or 'downvoted' by user. `false` otherwise.
```js
  comment.downvote(user);
  comment.voted(user);    // true
  comment.upvote(user);
  comment.voted(user);    // true
```

### .upvotes()
  Returns Number of `upvotes` count.
```js
  comment.downvote(user);
  comment.upvotes();      // 0
  comment.upvote(user);
  comment.upvotes();      // 1
```

### .downvotes()
  Returns Number of `downvotes` count.
```js
  comment.downvote(user);
  comment.upvotes();      // 1
  comment.upvote(user);
  comment.upvotes();      // 0
```

### .votes()
  Returns Number of `votes` count.
```js
  comment.downvote(user);
  comment.votes();          // 1
  comment.upvote(user);
  comment.votes();          // 1
  comment.downvote(user2);
  comment.votes();          // 2
```

## Test

```
  $ npm install --dev
  $ make test
```
## License

  MIT

---
_Source: https://npm.io/package/mongoose-voting · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
