node package manager



This plugin let you add an auto increment field to your schema.


  • Node.js, a server-side JavaScript implementation,
  • MongoDB, a NoSQL database,
  • Mongoose, an elegant Object Document Mapper for MongoDB.


Install it from NPM as you always do it with other packages.

npm install mongoose-pureautoinc

Available options

  • model - required parameter, name of your Mongoose model
  • field - name of your field
  • start - first value of your field which will be used

How to use

You can run example using this command:

$ node examples/example.js

Firstly, you need to require Mongoose and the plugin.

var mongoose     = require('../node_modules/mongoose'),
    Schema       = mongoose.Schema,
    db           = mongoose.createConnection('', 'yourDatabaseName'),
    pureautoinc  = require('pureautoinc');

Secondly, you need to initialize the plugin, define your schema and connect the plugin to it.

var schema = new Schema({
    email: String,
    text:  String
schema.plugin(pureautoinc, {
    model: 'Subscriber',
    field: 'recordNum'

After that you can create your model and use it as you wish.

var Subscriber = db.model('Subscriber', schema);

For developers

You should use Git pre-hook to validate your changes. Just copy pre-commit file into ./git/hooks/ directory.
In order to run tests manually execute $ vows --spec tests/*
In order to test performance of the plugin execute $ node benchmarks/benchmark.js


© 2012 MyLove Company, LLC. Source code is distributed under CDDL 1.0 open source license.