B
B
BogdanZots2021-10-11 10:45:16
Mongoose
BogdanZots, 2021-10-11 10:45:16

How to auto increment id for every element in mongoose?

Hello everyone, can anyone tell me how to edit the model for the table in mongoose so that each element would have an id that was auto-incremented when added? Thank you .
This is how I describe the model now:

const { Schema, model  } = require("mongoose");

const UserSchema = new Schema({
  email: { type: String, unique: true, required: true },
  firstName: { type : String, required: true },
  lastName: { type : String, required: true },
  password: { type: String, required: true },
  isActivated: { type: Boolean, default: false },
  activationLink: { type: String },
  _id: { type: Number }, // ??? Что тут нужно написать ? 
});

module.exports = model("User", UserSchema);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GlazOtca, 2021-10-11
@BogdanZots

Here you can read how to do it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question