Creating unique index in mongodb using mongoose

I'm creating a bot using mongodb and mongoose.js. I've defined a schema and am collecting data but have noticed that I can't add records with duplicate ID's.

I've confirmed that mongoose has created an index for my ID field. Is an index required? If so, is there a way to auto generate an unique id for the index?

It's MongoDB that creates index for _id field, not Mongoose. If you want your ids to be unique, either ensure uniqueness on your side or don't specify _id field at all in the insert.

Default type of _id field is ObjectId. It's designed to be unique, so you can safely generate these ids in the app and send to the database.