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.