I need to locate a specific object within an array, then insert additional data next to the matching key/value pair. Here is a sample scenario:
profile = [
{
data: 'value',
array: [
'one',
'three'
]
}
]
var i = 0;
var selector = 0;
_.each(profile, function(elem) {
if (elem.data === 'value') {
selector = i;
}
i++
}
profile[selector].array.push('two');
While this method works for adding to an array of objects/arrays, I'm looking for a way to achieve the same result using Meteor MongoDB. Is there a selector that allows me to pinpoint the correct array (based on a matching key/value pair) and then add new elements to the adjacent "array"?