mongoose-naxmefy-autoinc-fielddeprecated

mongoose plugin for auto incremented fields

Usage no npm install needed!

<script type="module">
  import mongooseNaxmefyAutoincField from 'https://cdn.skypack.dev/mongoose-naxmefy-autoinc-field';
</script>

README

mongoose-naxmefy-autoinc-field

mongoose plugin for auto incrementing fields

npm version

Build Status Coverage Status

NPM

installation

$ npm install --save mongoose-naxmefy-autoinc-field

usage without options (ModelName as String)

var mongoose = require("mongoose");
var autoIncLib = require("mongoose-naxmefy-autoinc-field");
var autoIncPlugin = autoIncLib(mongoose);

//...

var MyModelSchema = new mongoose.Schema({
  //...
});

// This will add field "autoIncId"
MyModelSchema.plugin(autoIncPlugin('MyModel'));

//...

var MyModel = mongoose.model('MyModel', MyModelSchema);

options for autoIncLib

var mongoose = require("mongoose");
var autoIncLib = require("mongoose-naxmefy-autoinc-field");
var autoIncPlugin = autoIncLib(mongoose, {
  collection: 'MyAutoIncCollection' // Name of collection which stores the auto inc counters
});

//...

options for autoIncPlugin

var mongoose = require("mongoose");
var autoIncLib = require("mongoose-naxmefy-autoinc-field");
var autoIncPlugin = autoIncLib(mongoose);

//...

// This will add field "autoIncId"
MyModelSchema.plugin(autoIncPlugin({
  model: "MyModel", //name of this model
  field: "myModelId", // field for auto inc
  startAt: 500, // start counter (not the first!!!)
  incrementBy: 114 // increment value (first will be startAt + incrementBy - here 614)
}));

//...

contributing

found bug? create issue!

missing feature? fork, implement and start pull request...or be lazy and create an issue...

license

MIT