Skip to content

Counts.get() delivers zero even though MongoDb console and server show count > 0 #75

@a4xrbj1

Description

@a4xrbj1

Autopublish package is removed. Here's the code in counts.html:

if (Meteor.isServer) {
    Meteor.publish('jobCompleted', function() {
        Counts.publish(this, 'numJobCompleted', myJobs.find({status: {$eq: "completed"}}));
    });

    Meteor.publish('atDNA', function() {
        Counts.publish(this, 'numAtDNA', Gedmatches.find({ atTotalCm: {$exists:true} }));
    });
}

if (Meteor.isClient) {
    Meteor.subscribe('jobCompleted');
     console.log('Number of jobs completed (client): ', Counts.get('numJobCompleted'));

    Meteor.subscribe('atDNA');
    console.log('Number of atDNA matches (client): ', Counts.get('numAtDNA'));
}

Output in the browser console is:

Number of jobs completed (client): 0
Number of atDNA matches (client): 0

Whereas the same query:

console.log('Number of jobs completed (server): ' + myJobs.find({status: {$eq: "completed"}}).count());
console.log('Number of atDNA matches (server): ' + Gedmatches.find({ atTotalCm: {$exists:true} }).count());

executed on the server (and in Mongodb shell) gives:

Number of jobs completed (server): 207
Number of atDNA matches (server): 51

I'm not sure what I'm doing wrong, tried to copy everything from the documentation. FYI - A normal find with a pub for all records (without further filter) find all records and works.

Thanks in advance for your help!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions