How to set primary key in mongoose?
Answer / 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 |
Which are the different languages supported by mongodb?
Will there be journal replay programs in case of incomplete entries (if there is a failure in the middle of one)?
Can we store pdf in mongodb?
What is a namespace in mongodb?
What is the role of use command?
Why mongodb data files so large (in size)?
Can mongodb store files?
Where is the mongodb data stored?
Does mongodb use sql?
Now days, what makes mongodb best?
What is syntax of for loop in r?
What is mongodb named after?
Oracle (3253)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)