I have a schema like this:
const sessionCardSchema = new Schema(
{
unit: Number,
creator: String
}
);
I can save a card like this:
const Card = {
unit: 2,
creator: 'Jack'
}
const sessionCard = new db.SessionCard(Card);
await sessionCardModel.save();
The issue is I cannot save my own objectId as _id of the document.
Here is what I tried:
My schema:
const sessionCardSchema = new Schema(
{
// _id: mongoose.Schema.Types.ObjectId,
unit: Number,
creator: String
}, { _id: false }
);
My code:
const Card = {
_id: '657c95a4b6e31b1c968aec94'
unit: 2,
creator: 'Jack'
}
const sessionCard = new db.SessionCard(Card);
await sessionCardModel.save();