You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to make this work with two schemas in my app and I cant seem to figure it out. I found a reference to someone else with an issue here and used their solution as a guide but its not working. I have 2 schemas set up, "userSchema" and "petSchema". Below each schema I have:
But when I try to use the schemas, I get this error:
C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose-sequence\lib\sequence.js:170
throw new Error('Auto increment field already present and not of type "Number"');
^
Error: Auto increment field already present and not of type "Number"
at SequenceFactory.Sequence._createSchemaKeys (C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose-sequence\lib\sequence.js:170:13)
at SequenceFactory.Sequence.enable (C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose-sequence\lib\sequence.js:112:10)
at SequenceFactory.Sequence.getInstance (C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose-sequence\lib\sequence.js:95:14)
at Schema.plugin (C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose\lib\schema.js:1430:3)
at Object. (C:\Users\ponyp\Desktop\MiwV2\APP.JS:61:12)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
Can you please help me figure out what's going wrong? I am still a beginner and I'm having a hard time figuring out what's up. I gather it's not giving the newly made pet an ID number but I can't tell why.
The text was updated successfully, but these errors were encountered:
Can you send the schemas (relevant part) and the plugin instantiation? Can you please try to better format the code (use backtick ` or the button < >).
Can you try to assign two different ids to the autoIncrement? Something like this
Also, is primaryKey: true part of mongoose 🤔 ? I think it's not, you have to define an index on the id field if you want to simulate the effect of a primary key.
I've been trying to make this work with two schemas in my app and I cant seem to figure it out. I found a reference to someone else with an issue here and used their solution as a guide but its not working. I have 2 schemas set up, "userSchema" and "petSchema". Below each schema I have:
userSchema.plugin(AutoIncrement, {collection_name: 'counters'});
and
petSchema.plugin(AutoIncrement, {collection_name: 'petCounters'});
as a part of them both, the schemas have:
id: {
type: Number,
primaryKey: true
},
But when I try to use the schemas, I get this error:
C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose-sequence\lib\sequence.js:170
throw new Error('Auto increment field already present and not of type "Number"');
^
Error: Auto increment field already present and not of type "Number"
at SequenceFactory.Sequence._createSchemaKeys (C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose-sequence\lib\sequence.js:170:13)
at SequenceFactory.Sequence.enable (C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose-sequence\lib\sequence.js:112:10)
at SequenceFactory.Sequence.getInstance (C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose-sequence\lib\sequence.js:95:14)
at Schema.plugin (C:\Users\ponyp\Desktop\MiwV2\node_modules\mongoose\lib\schema.js:1430:3)
at Object. (C:\Users\ponyp\Desktop\MiwV2\APP.JS:61:12)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
Can you please help me figure out what's going wrong? I am still a beginner and I'm having a hard time figuring out what's up. I gather it's not giving the newly made pet an ID number but I can't tell why.
The text was updated successfully, but these errors were encountered: