[SOLVED] Two publications adding to the same document are overriding each other


I stumbled upon something I thought I understood, but I clearly don’t.

Meteor.publish('users-counts', function(username){
	var fields = {
	return Meteor.users.find({username: username},{fields: fields})
	var fields = {
	return Meteor.users.find({username:username},{fields:fields})


When I go to some pages, I only need users-counts, which justifies decoupling the subscriptions. When I go to the profile page, I need ALL of the data, so I subscribe to both users-counts and users-profile. But when I check to see what the server sent down, it only sent down the fields published by users-profile.

A fix might be to just publish all of the data in users-profile also, but keep the users-counts for when I only need the counts data. But, if I already publish users-counts before, then wouldn’t that be a waste? I am pretty sure Meteor checks the server cache for that connection and only sends down diff-ed data, so it might not be a waste.

Any clarification or help would be appreciated.


How to publish nested fields that arent arrays

This is a classic problem with the Meteor pub/sub model. First level fields from separate publications are cleverly integrated, but nested fields are not. See this issue.

When I had to deal with this, I just ended up solving it in the most inefficient way possible by overpublishing a crapload of nested data for some scenarios, just to make sure it was there for others. I’m still looking for a good pattern to work around this.


@babrahams yikes! That’s exactly what I ended up doing. But I think I might just top-levelify everything by bypassing the user.profile.

Nesting isn’t mission critical for me, thankfully. It’s because of this silly “profile” construction…

That’s quite unfortunate, though. Intuitively, one would expect it to work. Thanks for your reply. :smile:


Yes, I’ve learnt from that experience to keep everything as top-level as possible and just prefix field names rather than nest in subdocuments.