Error in getting referenced objects in admin-bro Nodejs (There are no resources with given id)

1.6k Views Asked by At

So the error I am getting is There are no resources with given id: "workshop.timelines"\nThis is the list of all registered resources you can use.

This is the resource I am trying to visualize in adminbro

const LearnerSchema = new mongoose.Schema(
  {
    workshops: [
      {
        workshop: {
          workshop_id: {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'workshop',
          },
          code: {
            type: String,
          },
          timeline: {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'workshop.timelines',
          },
        },
    ],
  { timestamps: true }
);

This is the workshop model:

const WorkshopSchema = new mongoose.Schema(
  {
    name: {
      type: String,
      required: true,
    },
    description: {
      type: String,
    },
    timelines: [
      {
        group: {
          type: Number,
        },
        city: {
          type: mongoose.Schema.Types.ObjectId,
          ref: 'city',
        },
        description: {
          type: String,
        },
        venue: {
          type: mongoose.Schema.Types.ObjectId,
          ref: 'venue',
        },
        month: {
          type: String,
        },
        start: {
          type: Date,
        },
        end: {
          type: Date,
        },
        registration_start: {
          type: Date,
        },
        registration_end: {
          type: Date,
        },
        registrations: {
          type: Number,
          default: 0,
        },
        registrations_cancelled: {
          type: Number,
          default: 0,
        },
        d_reg: {
          type: Number,
          default: 0,
        },
        classLink: {
          type: String,
          default: '',
        },
        status: {
          type: String,
          default: 'E',
        },
        resources: {
          _id: false,
          videoSessions: { type: Boolean, default: false },
        },
      },
    ],
    status: {
      type: String,
      enum: ['NEW', 'F', 'DISABLED'], //f = FEATURED
      default: 'NEW',
    },
  },
  { timestamps: true }
);

WorkshopSchema.index({ name: 'text', description: 'text' });

module.exports = Workshop = mongoose.model('workshop', WorkshopSchema);

Now, I have added both of these resources among others in my adminbro options, but when adminbro tries to fetch some records from the Collection, it fails with the error:

There are no resources with given id: "workshop.timelines"\nThis is the list of all registered resources you can use.

One more thing that might be affecting this issue is that in MongoDB the value of timelines in the workshop object is a mix of ObjectId and string, however I have tried converting all the object values to ObjectId but it still shows the same error.

Would really appreciate any help here.

2

There are 2 best solutions below

0
On

had the same issue.

Basically, any ref model that appears in the models that are included in the resources array has to be included as well.

In your case, I will suggest to have a look at the ResourceOptions (https://adminbro.com/ResourceOptions.html) to see if you can included the nested property

0
On

comment out you're every (type: mongoose.Schema.Types.ObjectId,) to like this ↓↓ or you can delete it as well.

// type: mongoose.Schema.Types.ObjectId,

and it will work fine.

This is not working because by default, Mongoose adds an _id property to your schemas and you are explicitly defining it so need to explicitly insert it while creating but in AdminBro Dashboard you do not have that kind of option to add _id while creating any new Object. So, for that reason comment every _id generating field.