Publication data disappears from minimongo

#1

so I created a view in my database using the command

db.createView('testViewUSA',"collection", [{
 $group: { 
     _id:null,
      count: { $sum: 1 } }
}, 
{
     $project:{
           _id: "test", count:1 
    }
 }])

I have meteor read it as a collection as so testViewUSA;

import {Mongo} from "meteor/mongo"; 

export const testViewUSA = new Mongo.Collection('testViewUSA');

I also have a publication

Meteor.publish({
 'testViewUSA.all': function(_id) { 
      isUserLoggedIn(this.userId);
      console.log('my view data', testViewUSA._name);
      return testViewUSA.find({ _id }); 
},
});

the subscription being used on the client is here

Template.test.onCreated(function() {
     // filler
     this.subscribe('testViewUSA.all', "test")
    // filer 
});

and a helper on the client

getCount() {
     const countData = testViewUSA.findOne({});
     console.log('countData', countData); 
     return countData; 
},

for some reason the data loads and then after a couple of seconds the web socket returns this message

"{"msg":"removed","collection":"testViewUSA","id":"test"}"

rather than updating when the data changes

can you help me

#2

I’m not sure of this, but try the following:

Change publication to

Meteor.publish({
 'testViewUSA.all': function(_id) { 
      isUserLoggedIn(this.userId);
      // console.log('my view data', testViewUSA._name);
      return testViewUSA.find(_id); 
},
});

change subscription to

Template.test.onCreated(function() {
     // filler
     this.subscribe('testViewUSA.all', { _id: "test" })
    // filer 
});

and change helper to

getCount() {
     /* see "Always use specific queries to fetch data" at 
    https://guide.meteor.com/data-loading.html#fetching
    */
     const countData = testViewUSA.findOne({_id: "test"}).fetch();
     console.log('countData', countData); 
     return countData; 
},