1.0.1 • Published 8 years ago

elo-mongoose v1.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

elo mongoose plugin

npm.io

A mongoose plugin that adds the ability to use the elo rating system on a model. Built using my elo-rank library. Note: only tested on node v5.0.0

example

const mongoose = require('mongoose');
const eloPlugin = require('elo-mongoose');

let schema = new mongoose.Schema({
    name: String
});

schema.plugin(eloPlugin);

const TestModel = mongoose.model('TestModel', schema);

TestModel.create({
    name: 'test',
    rating: 1500
}, (err, model) => {
    console.log(model.rating) // => 1500

    // First id is the winner
    TestModel.updateRatings(model.id, someOtherId, (err, models) {
        //returns both models with their update ratings
        console.log(models);
    });
});

api

  • model.rating the added rating column
  • Model#updateRatings used to save a match outcome
  • Model#sortByRating returns a chainable mongoose query object sorted by rating, if a callback is provided it executes the query

license

do wutever u want whenever u feel like it