I need to run a find on a particular mongo collection and retrieve a particualr value which is embedded. I tried running the raw query on mongo directly and it works. However, when I try it from within the template helper, I seem to run into syntax errors. Can someone show me the right syntax?
Sample collection:
{
name: a,
age: 10,
address: {
street: X,
area: Y
}
}
I need to search using street and arrive with area.
db.Collection.find( name:a, age:10, “address.street”: X) --> This fetches the entire record in mongo shell.
But when I try the same in a helper, I run into syntax errors. I’ve tried address[‘street’] , address:{street: X} but to no success.
What I did is mapped the query such that I ended up with an array of objects. Now, I need to find only a subset within this array of objects and return it to {{#each}} but it somehow seems that _.find isn’t returning any array.
var result = Collection.find({....}).map(....);
result currently contains:
result = [{key: A, value: 'foo'}, {key: A, value:'bar'},{key: B, value:'bar}]
Then I did:
result2 = _.find(result, function(obj) { return obj.name == A });
However, when I return result2, I get the following error:
Error: {{#each}} currently only accepts arrays, cursors or falsey values.
How exactly do I return all value for which key is A?