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.
CodePudding user response:
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]