Problem with publish/subscribe in React

Hello I have this problem and maybe you can help.
I have a collection who comes from a different database as the others, and I created the collection like

const db2 = new MongoInternals.RemoteCollectionDriver(...);
const JtiJobs = new Meteor.Collection('jobs',{ _driver: db2,  _suppressSameNameError: true } )

then I wrote my publication as

Meteor.publish("JtiJobs", function(args) {
  return JtiJobs.find(args);
});

Until this point everything works great, I can get all the data I want on the backend without any problems, but I wrote a component to show that data on the frontend and I used the withTracker HOC as I’m using react

export default withTracker({
  getMeteorData () {
    const handlerJob = Meteor.subscribe('JtiJobs', {_id: "QNdRnbR2YFkf62eq3"})
     
    const userId = Meteor.userId();
    
    return {
      currentUser: Meteor.user(),
      listLoading: !handlerJob.ready(),
      jobs: JtiJobs.find({}).fetch(),
    };
  },
  pure: true,
})(Charges);

When accessing the listLoading prop it works as expected it says true for a moment and then it loads and says false, but the data never loads in this.props.jobs.
Maybe I’m missing something but I followed every tutorial I could find and I don’t see where I’m wrong.
Thank you for the help :slight_smile:

Where is your Oplog for db2? I think that is necessary for reactivity.

1 Like

@paulishca thanks for your answer, the second database is also used on a different meteor app and has set up a Redis replica for Oplog, but indeed I didn’t configure anything on this application for the Oplog of that second database.
How should I do it?
I know how to configure the Oplog at the application level but never configured it for a individual database

I will have to leave this to someone who’s done this before. I personally don’t think you can be reactive with two different DBs based on Oplogs.
I hope not to mislead here… You could look into observers which is basically the link I shared with you earlier or here: ([Solved] Meteor observe not working properly in 1.6) or since you use the Mongo Driver, perhaps directly Mongo tech like https://docs.mongodb.com/manual/reference/method/db.collection.watch/. If not too critical I’d go with polling. Another way is to keep a “trigger” on your main DB if you need to update based on Inserts. Example:

I save all teams and team members in a “secondary” DB.
In my main DB I keep a collection of the number of team members in a team. (When I write a team member to a team in DB2 I also increment the counter in DB1.) I subscribe to DB1 (for which I use the Oplog). In React, with a useEffect() dependent on the counter, I pull data if the counter changes. I never observe/subscribe data sets. In most cases for Insert/Remove records it is so much cheaper to observe counters in counters collections. In case of Updates of documents it is a different story :).