To set ObjectId as a data type in Node Mongoose, we set the value to ObjectId
.
For instance, we write
const mongoose = require("mongoose");
const Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
const SchemaProduct = new Schema({
categoryId: ObjectId,
title: String,
price: Number,
});
to set the categoryId
property to ObjectId
to make categoryId
an object ID field.