Reputation: 263
I have a database of about 10,000 items. About a search I get an array of 10 IDs.
for example:
getProduct("pizza") --> [ "rjxyykii7gx9MQYZb", "JCh45MFwQHEHXRG3s", "FLRkf5jQDMLef4wzL", "76BbqHMumrpQ8u9h6", "4Mfr4EbrmiexA6tgG", "QT4mqbK59BpsR8nPj", "HnNEBaBPf3kGJeg47", "fjJJtZbYFXF9RBCep", "LrBhnTMxgA2mwpYmB", "CXEwwxWDQYgiGKEpG"]
Now I want, to save recources, set a limit of 10 items
Server:
Meteor.publish("artikel", function () {
return Artikel.find({}, {limit: 10});
});
Client:
Meteor.subscribe('artikel');
But now I get no result list:
var cursor = Artikel.find({_id: {$in: idArray}});
cursor.count(); //--> 0
if I use my database-tool, I get, with the same values, 10 results
db.artikel.find({_id: { $in: [ "rjxyykii7gx9MQYZb", ... ] } }).limit(10).count() //--> 10
what am I doing wrong? Thank you.
Upvotes: 0
Views: 185
Reputation: 3288
The problem is you're publishing 10 records to the client. The reason your count is returning 0 is there's a very small chance the ten records you're publishing are within the idArray. You want your $in to be in the publish function, like so (I would also add a skip):
// server
Meteor.publish("artikel", function (idArray, skip) {
return Artikel.find({_id: {$in: idArray}}, {limit: 10, skip: skip});
});
And then on the client:
// client
Meteor.subscribe('artikel', idArray, skip);
Artikel.find({}).count() // --> 10
Upvotes: 1