meteor - Inserting data of type String in Array within object which is in another array -


how can insert data of type string in array within object in array?

the below array:

productrequirements: [{     question: "what type of business bag need?",     type: "checkbox",     specifications: [         "luggage bag",         "handbag",         "shoulder bag",         "soft bag",         "laptop bag",         "tote bag",         "not sure",         "others"] }, {     question: "what kind of logo prefer on bag?",     type: "radio",     specifications: [         "oem",         "embossed",         "debossed",         "printed",         "customized",         "not sure",         "others"] }] 

i want insert strings in specifications 1 one , trying following code:

products.update({     _id: productid,     "productspecifications.specification": listing["specification"] }, {     $push: {         "productspecifications.$.options": {             options: listing["options"]         }     } }) 

which inserting object instead of string. how can rectify it?

i think issue set of curly braces around options:listing["options"]. current command telling push object options list.

perhaps try instead

products.update({_id:productid,"productspecifications.specification":listing["specification"]},                     {$push: { "productspecifications.$.options": listing["options"]                 }}) 

also - if listing["options"] array, $push push whole array single object, in case should use $each $push:

{$push: {field: {$each: [value1, value2]}}} 

also - consider using $addtoset instead of $push want maintain unique array elements. $addtoset works $each

{$addtoset: {field: {$each: [value1, value2]}}} 

hope helps, sure let me know!


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -