0

Im using mongoose-auto-increment to create and increase my item id. I would like to create index for this id but I haven't found a wayto achieve, insofar as I can look up on the Internet. Does anybody have any experience on creating an index for the custom field generated by mongoose-auto-increment?

J. C
  • 89
  • 11

1 Answers1

1

In first you have to install the plugin: $ npm install --save mongoose-sequence-plugin.
Here you have one example.

const mongoose = require('mongoose');
const AutoIncrement = require('mongoose-sequence')(mongoose);

const BarSchema = mongoose.Schema({ 
name: String,
email: String,
type:String,
location:String,
}, {
timestamps: true});BarSchema.plugin(AutoIncrement, {inc_field: 'idBar'});module.exports = mongoose.model('Bar', BarSchema);