Hello,
I’m trying to fill 2 Client side Collection from one which is server side only, reading around i tried to target specific collection with “Mongo.Collection._publishCursor”, but this just doesn’t seems to work. Is it a way to do this please?
Here is my code, the cursor is well filled in the publish callback but the client collection is not filled :
FoodsPublic = new Mongo.Collection("foods.public");
FoodsSearched = new Mongo.Collection("foods.searched");
...
Home = React.createClass({
mixins: [ReactMeteorData],
...
getMeteorData () {
Meteor.subscribe('foods.public', this.state.requestedFoods, this.state.nameSearched);
Meteor.subscribe('foods.searched', this.state.requestedFoods, this.state.nameSearch);
let query = {};
return {
foodsPublic: FoodsPublic.find(query).fetch(),
foodsSearched: FoodsSearched.find(query).fetch()
};
},
...
});
on Server :
Foods = new Mongo.Collection("foods");
setPublishCollectionSimple = function (sub, cursor, collectionName) {
Mongo.Collection._publishCursor(cursor, sub, collectionName);
sub.ready();
}
foodByLimitAndSearch = function (limit, nameSearch, collectionName, sub) {
let query = {};
let options = {
sort: {food_id: 1},
limit: Math.min(limit, MAX_FOODS)
};
if (nameSearch.length) {
const searchRegex = new RegExp(nameSearch, 'i');
query.name = { $regex: searchRegex }
}
console.log("Requesting Food : ", {query:query, options:options})
//This cursor is filled correctly i can get the data in debugger
const cursor = Foods.find(query, options);
setPublishCollectionSimple(sub, cursor, collectionName)
}
Meteor.publish("foods.public", function (limit, nameSearch) {
foodByLimitAndSearch(limit, nameSearch, 'FoodsPublic', this);
});
Meteor.publish("foods.searched", function (limit, nameSearch) {
foodByLimitAndSearch(limit, nameSearch, 'FoodsSearched', this);
});