Reputation: 57
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
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