mongoose-pureautoinc

2012.1.0 • Public • Published

mongoose-pureautoinc

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

Requirements

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

Installation

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('127.0.0.1', 'yourDatabaseName'),
    pureautoinc  = require('pureautoinc');

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

pureautoinc.init(db);

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

Copyright

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

Dependents (0)

Package Sidebar

Install

npm i mongoose-pureautoinc

Weekly Downloads

5

Version

2012.1.0

License

none

Last publish

Collaborators

  • mylovecompany