Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

using ObjectId as a data type

I’m trying to create a schema for an object and I’m using ObjectId as type but he gives me an error

const mongoose = require("mongoose");

const permissionsSchema = new mongoose.Schema({
 roleId: {
   type: ObjectId,
   required: true,
 },
 menuPageId: {
   type: ObjectId,
   required: true,
 },
 readAccess: {
   type: Boolean,
   required: true,
 },
 createAccess: {
   type: Boolean,
   required: true,
 },
 editAccess: {
   type: Boolean,
   required: false,
 },
 deleteAccess: {
   type: Boolean,
   required: false,
 },
});

const Permissions = mongoose.model("Permissions", permissionsSchema);
module.exports = Permissions;

ERROR

type: ObjectId,
ReferenceError: ObjectId is not defined

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Replace ObjectId with

mongoose.ObjectId

Or

mongoose.Types.ObjectId

Reference

Mongoose – ObjectIds

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading