Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the data type of _id in MongoDb

I want to create a user Schema using moongose. In user Schema i want to keep the ids of the blogs which written by the user. So what should be the data type of ids.

blogIds:{
    type: ???,
    require: true,
}

I thought that it can be String but I haven’t tried.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can get import the type ObjectId from mongoose:

import mongoose, { Schema } from 'mongoose';


.
.

blogIds:{
    type: [Schema.Types.ObjectId],
    require: true,
}

If not using ES6 import, then simply:

type: [mongoose.Schema.Types.ObjectId]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading