Pub/Sub in the split client and server repo

I have split the client and server repo.
client-side

import/ui/App.jsx

const meteorAppBaseUrl = Meteor.settings.public.API_BASE_URL;
export let remote = DDP.connect(meteorAppBaseUrl);
const user =Meteor.user();

import/collections/equipment.js

import { Mongo } from 'meteor/mongo';
export const EquipmentCollection = new Mongo.Collection('equipmentTypes');

import/ui/EquipmentType.jsx

const EquipmentType =({user})
=>{
 remote.subscribe("equipment", user);
  const equipment = useTracker(() => EquipmentCollection.find({ companyId: user?.profile?.companyId, isDeleted: false }).fetch(), [])

  console.log(":rocket: ~ EquipmentTypes ~ equipment:", equipment)
return(
Other code 
)
}

It comes the empty array equipment types.

server side

import/publication/equipment.jsx

Meteor.publish("equipment", function (user) {
console.log("Publication triggered");
  const companyId = user?.profile?.companyId;
  if (companyId) {
    const data = EquipmentCollection.find({ companyId: companyId, isDeleted: false });
    return data;
  } else {
    return [];
  }
});

import/collections/equipment.js

import { Mongo } from 'meteor/mongo';
export const EquipmentCollection = new Mongo.Collection('equipmentTypes');

The client and server are separated into different repositories, with the server-side connected to the client via a DDP connection.

On the client side, the “equipmentCollection” in MiniMongo is created, but it’s empty array. However, data from the “users” collection is successfully fetched from the database.

In actual mongoDB mongodb://localhost:3001/equipmentTypes it contains the data.

I know that it is silly question. But I am stuck here.

Hi,

@akashcrest, I hope you are doing well. We are also fine. Thanks for asking.

Welcome to the community.

If you really really really want someone to really really really get back to you, please format your code.
You can do that by writing your code in snippets with the use of 3 backticks ` at the beginning and another 3 at the end.

Screenshot 2024-05-06 at 3.05.50 PM

Cheers,
P

1 Like

Thanks for advice me.

Hey, I am not sure if you mentioned your Meteor version. Could this be the culprit in your case - the “asyncification” of Mongo methods? react-packages/packages/react-meteor-data at master · meteor/react-packages · GitHub

Hi @paulishca , I am using the meteor version 2.15 . Here, I have tried the “async” but the promise get “fulfilled” and still return the empty array.