Answer Posted / Sah Navneet Kumar Ramsuraj
In Mongoose, you can set a primary key by defining the schema's `_id` field and setting its type to your desired data type. For example, for a user model with an auto-incrementing primary key:
const mongoose = require('mongoose');
const { Schema } = mongoose;
const UserSchema = new Schema({ _id: {type: Number, unique: true, autoIncrement: true}});
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers