If I remove this line {info: {dishType: { $in : this.whens }}} is finding the plates well but both are not working together, the result always is empty.
If I have selected onion and lunch I want to see plates maybe with more information in ingredients (not just onion) and with info but should have this combination of parameters.
I suspect this.whens needs to be an array of strings (like [ 'potato', 'kale', 'carrot' ]) and the dishType field needs to be a simple string (like 'broccoli'). From the MongoDB doc for $in:
The $in operator selects the documents where the value of a field equals any value in the specified array.
I can see my collections with show collections but db.food.findOne().pretty() returns me this:
TypeError: Cannot call method ‘pretty’ of null
But anyway, if you want to see what contents one plate in food is this:
// ...some properties skipped
date: new Date(),
ingredients: ['rice', 'fish', 'sesame'],
recipe: [{text: 'Well, you should order a sushi restaurant to take away and say you made it'}],
info: {
time: 30, servings: 5, dishType: 'Dinner', region: 'Japan', summary: 'The famoust plate from Japan'
},
likes: [],
// ...some properties skipped
I have changed the controller which is listing the food so I’m applying the filter directly to be more sure (and don’t do more steps to check this out).
Resuming of the problem: I get 5 plates while with minimongo I get 6 (which is the correct number) with the same query.
This was my controller:
this.perPage = 21;
this.sort = {
date: -1
};
this.subscribe('food', () => [{
limit: parseInt(this.getReactively('perPage')),
sort: this.getReactively('sort')
}
]);
// find() was NOT the problem
I’ve got a lazy loading for my plates. If we scroll till the 21st (default number) we load more.
BUT with 21 I can see 5 results. If I change it to 28 I’m able to see the 6 results.
If I still scrolling the app doesn’t find more plates, so doesn’t load more.
And the problem is not obviously related with this number, if I specified the limit in 6 I see 3 results.
After a few days working in a different thing I came back into this again…
In my publish function I’m forcing the limit: return Food.find(selector, {limit: 2});
And in my subscription I’m passing some details to show the third plate in my Food collection.
When I reload my app to see my plate I cannot see anything but if I change this limit to 3 I can see my plate.
(I’m using Robomongo always to see before the correct result)
So this limit is not a limit for my results is a limit for the normal collection. I’m not limiting my search to 3, I’m limiting the collection to search into it to 3!
Is this the normal behavior?
I so, how can I change this to filter just 3 results?
Cheers!
Edit: I just found the problem here
I had to filter in the publish function, no in the Mongodb query