orloff
November 8, 2016, 12:37pm
1
After removing autopublish deadlock condition:
// lib/collection/collections.js
Cart.Items = new Mongo.Collection('cart-items');
// imports/api/server/publications.js
Meteor.publish('cartItems', function(dataQuery) {
return Cart.Item.find(dataQuery);
});
// imports/startup/client/routes/cart.js
items:Meteor.subscribe('cartItems',dataQuery)
console.log(items);
Object: ready()
stop()
subscriptionId: "LGgNZKueYjczMhbsr"
__proto__:.......................................
question: how to get data from this sub?
what is wrong?
orloff
November 8, 2016, 1:49pm
3
oops, boner
fixed,
now
Exception from Tracker recompute function:
meteor.js?hash=ae8b8af…:930 Error: {{#each}} currently only accepts arrays, cursors or falsey values.
with autopublish was no problems, how to debug it?
@orloff seems you lack the fundamentals of subscriptions. Please give a read http://www.meteor-tuts.com do the walkthrough it will clear a lot.
For your case I asume in your helper you return a cursor:
return Collection.find()
Instead you should return
return Collection.find().fetch(); // which is an array
orloff
November 8, 2016, 2:18pm
5
if in publication i change Collection.find(); to find().fetch(), then:
Exception from sub cartItems id uDGazJXw48toheM2E Error: Publish function returned an array of non-Cursors
Meteor.subscribe i using in ironrouter’s render with data:
this.render('CartItems', {
data: renderData
});
where
renderData= ()=> {
return {
items:Meteor.subscribe('cartItems',dataQuery),
}
}
Man, you are mixing up concepts. Please read the tutorial I gave you.
orloff
November 9, 2016, 7:11am
7
thanks for meteor-tutor link)
Meteor.subscribe('donuts')
var donats = DonutsCollection.find().fetch()
console.log(donats);
// undefined
please explain, how to fetch data from local minimongo, just after subscribe is ready?
probably need some asynchronous callback function?
within which I will collection.find()?
orloff
November 9, 2016, 12:25pm
8
after add
onReady: function() {
collection.find()
}
worked ok,
big thanx for help)