I’m a little stuck.
I have a collection setup something like
{
_id: someIdHere,
name: {
first: Brian,
last: McGonagill
},
phone: {
home: 800-555-1234,
cell: 800-444-1414
},
gender: M,
gifts: [{
giftNo: 1,
giftType: Pajamas,
giftSize: XL,
},
{
giftNo: 2,
giftType: Winter Hat,
giftSize: 9 1/2,
},
],
I’m running a query to try and get only one gift from the array by giftNo. It works in the Meteor Mongo cli, as follows:
db.recipients.find({ _id: "DKnjEEE9rGpFqJcAW", "gifts.giftNo": "2" }, { "gifts.$": 1 })
Of course in code I replace the ID number with a variable, and the gift Number with a variable. In the CLI this gives
{
"_id" : "DKnjEEE9rGpFqJcAW",
"gifts" : [
{
"giftNo" : "2",
"giftType" : "Winter cap&scarf",
"giftSize" : "one size fits all",
}
]
}
Which is what I want.
When I use it in a helper, however, and I do
{{#each myHelperFunction}}
{{giftType}}
{{giftSize}}
{{/each}}
I only get [Object], [Object]…so I added a second loop…
{{#each myHelperFunction}}
{{#each gifts}}
{{giftType}}
{{giftSize}}
{{/each}}
{{/each}}
This works, sort of, but I get all gifts and sizes for this _id. So, I did some testing, and it appears that Meteor is ignoring the last part of the query which tells Mongo that I only want the first match found, which in this case is only 1 gift.
Any help on how I can resolve this is much appreciated.