1

I'm getting null array value in main_categories. My schema is for brand collection:

Schema Definition

Schema.main_category = new SimpleSchema({
    name: {type: String},
    icon_image: {type: String},
    description: {type: String}
});
Main_Category.attachSchema(Schema.main_category);


Schema.brand = new SimpleSchema({
   name: {
       type: String,
   },
   admin_number: {
       type: String,
   },
   company_name: {
       type: String,
   },
   owner_name: {
       type: String,
   },
   owner_number: {
       type: String,
   },
   admin_comment: {
       type: String,
   },
   address: {
       type: Schema.address,
   },
   logo_image: {
       type: String
   },
   staffs: {
       type: Array
   },
   "staffs.$": {
       type: Object
   },
   "staffs.$.type": {
       type: String,
       allowedValues: ['admin']
   },
   "staffs.$.user_id": {
       type: String
   },
   main_categories: {
       type: [Schema.main_category]
   },
   sub_categories: {
       type: [Schema.sub_category]
   },
   showcase: {
       type: Boolean
   }
});

Brand.attachSchema(Schema.brand);

Implementation

"addBrandMethod": function(jsonData) {
   var json = {
       name: jsonData.brandName,
       admin_number: jsonData.adminNumber,
       company_name: jsonData.companyName,
       address: jsonData.companyAddress,
       owner_name: jsonData.ownerName,
       owner_number: jsonData.ownerNumber,
       admin_comment: "jsonData.adminComment",
       logo_image: "fasdfa",
       staffs: [{
           type: "admin",
           user_id: "jaskjjkj"
       }],
       main_categories: [{
               "_id": "uBibwEqaoDkZtXhsR",
               "name": "Hair",
               "icon_image": "nbdenck",
               "description": "Hair Cut with Massage"
           }
       ],
       sub_categories: Sub_Category.find().fetch(),
       showcase: true
   };
   Brand.insert(json);
   return "Success";
}
MasterAM
  • 16,283
  • 6
  • 45
  • 66
Pradeep Saini
  • 680
  • 6
  • 17

2 Answers2

0

Try removing the _id key from the main_categories array. You didn't specify the _id key in the schema and simple-schema will only add the key when it's a schema that's attached to a collection.

Henri Beck
  • 81
  • 2
0

I was getting main_categories object null because main_categories file alphabetically down from brand schema file.. and in brand schema file i was getting object of main_categories schema undefined. when i paste file up to brand schema file then problem solve..

Pradeep Saini
  • 680
  • 6
  • 17