ashwor11
ashwor11

Reputation: 57

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.

Upvotes: 0

Views: 723

Answers (1)

Tushar Shahi
Tushar Shahi

Reputation: 20441

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]

Upvotes: 3

Related Questions