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

Upvotes: 0

Views: 74

Answers (1)

Yong Shun
Yong Shun

Reputation: 51125

Replace ObjectId with

mongoose.ObjectId

Or

mongoose.Types.ObjectId

Reference

Mongoose - ObjectIds

Upvotes: 2

Related Questions