Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema.plugin() must be a function got object #18

Open
warlockdn opened this issue Apr 8, 2018 · 1 comment
Open

schema.plugin() must be a function got object #18

warlockdn opened this issue Apr 8, 2018 · 1 comment

Comments

@warlockdn
Copy link

I have a schema with

const mongoose = require('mongoose');
const autoIncrement = require('mongoose-plugin-autoinc');

// Initialize Auto Increment 
const connection = mongoose.createConnection("mongodb://localhost:27017/food");

const partnerSchema = new mongoose.Schema({
    partnerID: { type: Number, index: true, unique: true }
});

partnerSchema.plugin(autoIncrement, {
    model: 'Partner',
    field: 'partnerID',
    startAt: 100300,
    incrementBy: 3
});

When I run this I keep getting duplicate index error. Can you tell me where I am wrong ?

@nodkz
Copy link
Owner

nodkz commented Apr 20, 2018

Take a look at the collection identitycounter in your Database. It created by mongoose-plugin-autoinc and may contain an incorrect value for next counter.

So when you add a new record, identitycounter provide next value, eg (100). But in your collection, you already have a record with such id and MongoDB throws an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants