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

Getting Error: Cannot read property 'seq' of null #121

Open
sannminwin opened this issue Mar 17, 2022 · 1 comment
Open

Getting Error: Cannot read property 'seq' of null #121

sannminwin opened this issue Mar 17, 2022 · 1 comment

Comments

@sannminwin
Copy link

sannminwin commented Mar 17, 2022

I have installed
"mongoose": "^5.11.12",
"mongoose-sequence": "^5.3.1",

and use mongoose-sequence in mongoose Model file as below

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

const AlbumSchema = new mongoose.Schema({
userId: {
  type: Number,
},
title: {
  type: Object
},
genre: {
  type: Array
},
artists: {
  type: Array,
},
composers: {
  type: Array
},
releaseDate: {
  type: String
}
});

AlbumSchema.plugin(AutoIncrement, {inc_field: 'albumId'});

module.exports = mongoose.model('Album', AlbumSchema);

When I run Album.create(data) in controller I am getting this error

Screen Shot 2022-03-16 at 8 03 43 PM

@christohill
Copy link

Old issue, but I ran into this as well on newer versions:

"mongoose": "^7.7.0"
"mongoose-sequence": "^6.0.1"

I fixed it by creating the inc_field on the schema with type: Number

In this case:

Schema({
  ...
  albumId: { type: Number }
  ...
})

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