Linked Questions

Popular Questions

Find and make nested array from different collection mongoose

Asked by At

I have 3 collections

const mainCategorySchema = new Schema({
    rest_id: { type: Schema.Types.ObjectId, ref: 'restaurants', required: true },
    main_category_name: { type: String, required: true },
    main_category_slug: { type: String, required: true },
    main_category_desc: { type: String, required: true },
    sorting_order: { type: Number, default: 1 },
    main_status: { type: String, enum: ['1', '2', '3'], default: '1' }
});

const subCategorySchema = new Schema({
    rest_id: { type: Schema.Types.ObjectId, ref: 'restaurants', required: true },
    main_category_id: { type: Schema.Types.ObjectId, ref: 'maincategorymenu', required: true },
    main_category_name: { type: String, required: true }, 
    sub_category_name: { type: String, required: true },
    sub_category_slug: { type: String, required: true},
    sub_category_desc: { type: String, required: true },
    sub_status: { type: String, enum: ['1', '2', '3'], default: '1' }, //1-active, 2-in active, 3-blocked
    sorting_order: { type: Number, default: 1 },
});

const dishesSchema = new Schema({
    rest_id: { type: Schema.Types.ObjectId, ref: 'restaurants', required: true },
    main_category_id: { type: Schema.Types.ObjectId, ref: 'maincategorymenu', required: true },
    sub_category_id: { type: Schema.Types.ObjectId, ref: 'subcategorymenu', default: null },

    main_category_name: { type: String, required: true },
    sub_category_name: { type: String, default: '' },

    dish_name: { type: String, required: true },
    dish_slug: { type: String, required: true },

    dish_base_price: { type: Number, required: true },
    dish_vendor_price: { type: Number, required: true },
    dish_selling_price: { type: Number, required: true }
});

I am trying to find data, so i can display data according to the image Menu listing Image

I am new to mongo db and unable to figure out how to solve this issue. Thanks.

Related Questions