Any Idea why this is not working on the client?
On server I get the correct count but on client I get ‘0’
this is in /lib/collections.js:
if (Meteor.isServer) {
let database1 = new MongoInternals.RemoteCollectionDriver("mongodb://127.0.0.1:3001/HerbsDB");
export const Herbs = new Mongo.Collection("HerbsTable", { _driver: database1 });
let a = Herbs.find().count()
console.log(a);
Meteor.publish('Herbs', function() {
return Herbs.find();
});
}
if (Meteor.isClient) {
export const Herbs = new Mongo.Collection("HerbsTable");
Meteor.subscribe('Herbs');
let a = Herbs.find().count()
console.log(a);
}
on dev console I get:
Herbs.find()
VM7535:1 Uncaught ReferenceError: Herbs is not defined(…)
please comment this part and see if the error still there
if (Meteor.isClient) {
// export const Herbs = new Mongo.Collection("HerbsTable");
// Meteor.subscribe('Herbs');
// let a = Herbs.find().count()
// console.log(a);
}
and then this one
if (Meteor.isClient) {
export const Herbs = new Mongo.Collection("HerbsTable");
Meteor.subscribe('Herbs');
// let a = Herbs.find().count()
// console.log(a);
}
I should also point out that you aren’t waiting for the data to arrive in your subscribed collection, so you may want to check for the subscription ready before reporting.