Closed boxofrox closed 9 years ago
Without a field specifier, the accessor function causes publish-count to fetch entire documents, instead of only those fields necessary to maintain a proper count. The field specifier is recommended.
@kristijanhusak I take it the second solution from earlier didn't work with the field specifier [1]? If it does, then you won't receive the warnings.
I'm more inclined to have the debug option be opt-out rather than opt-in in development. Or if I can detect a production environment, disable the warning automatically. I'll take a look.
Notes to self.
process.env.NODE_ENV
to distinguish between development and production environments.Counts.noWarnings()
to disable all warnings in development. For single developers only. Not recommended for development teams.noWarn: true
to the options
parameter of Counts.publish()
to disable warnings in development per publish. Recommended for development teams.@boxofrox I tested that first solution again, it is working, but now i get both warnings
W20150812-11:59:15.770(2)? (STDERR) publish-counts: unused fields detected in cursor fields option { _groupId: 1, day: 1, user: 1 }
W20150812-11:59:15.775(2)? (STDERR) publish-counts: unused fields removed from cursor fields option. { _groupId: 0 }
I need to specify more fields because of the query, not just _groupId
. Here's the code:
Meteor.publish('calculateTasksTime', function(from, to, user) {
var tasks = Tasks.find({
time: {$gt: 0},
day: {
$gte: moment(from).startOf('day').unix(),
$lte: moment(to).endOf('day').unix()
},
user: user
}, {
fields: { _groupId: 1, time: 1, day: 1, user: 1}
});
Counts.publish(this, 'calculateTasksTime', tasks, {
countFromField: 'time'
});
});
Hope this is helpful to you.
@kristijanhusak wierd.
I think those two warnings are from separate Counts.publish
calls, otherwise the second warning would remove day
and user
also.
The first warning is expected for the code you provided, and I'm glad to hear that it works.
From #53