mongodb - Complex Meteor Publication Isn't Reactively Updating As Expected -
i'm working on meteor app uses several collections reference each other in tree-style organization. however, they're represented flat collections in database structure. illustration have top-level cars
collection, parts
collection , sellers
collection looks (pseudo-code):
cars { _id: make: model: year: etc... } parts { _id: carid: cars._id type: desc: etc... } seller { _id: partid: parts._id location: name: etc... }
so way reference each other in tree this:
car | ----> part | | | ----> seller | | | ----> seller | | | ----> seller | ----> part | ----> seller | ----> etc...
the problem i'm having utilize several top level publications pass car._id
, want see sellers
sell parts
car
. in route have subscribe looks this:
waiton: function() { homecoming meteor.subscribe('allsellersbycar', this.params._id); }
so homecoming sellers
car._id
fetch parts
match car._id
, utilize underscore _.pluck()
part._id
, find sellers
match array of part._id
:
meteor.publish('allsellersbycar', function(carid) { var parts = parts.find({carid: carid}).fetch(); homecoming sellers.find({partid: {$in: _.pluck(parts, "_id")}}); });
this method works fine , returns sellers
correctly. problem method reatively homecoming sellers
added existing parts
, template live update expected, not homecoming sellers
added new parts
added car
object. seems reactively updates lastly line of query. entire query doesn't rerun when new part
gets added. if refresh page (and hence route), query reruns , gets returned correctly.
i have multiple publications in app, of have several more "middle-man" fetches before returning. i'm not sure how prepare or problem is. going pub/subs wrong? should de-normalize references more , add together carid
each seller
can query straight on seller
collection in 1 line , not have go through parts
fetch?
mongodb meteor iron-router
No comments:
Post a Comment