[solved] Autopublish removed: publish-subscribe with "import" structure


#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?


#2

You are missing an “s” …


#3

oops, boner :grinning:
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?


#4

@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

#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),
}
}

#6

Man, you are mixing up concepts. Please read the tutorial I gave you.


#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()?


#8

after add
onReady: function() {
collection.find()
}
worked ok,
big thanx for help)