It seems that the publish works well, since I get the “Ready”, but when I’m trying to access my collection using the cursor, I get “Companies undefined”…
Uncaught ReferenceError: Companies is not defined
...
Exception from Tracker recompute function:
ReferenceError: Companies is not defined
They concerns the line I do “console.log(Companies.find())”
And here is my complete code for server side :
import { Meteor } from "meteor/meteor";
class CompaniesCollection extends Mongo.Collection {
insert(company, callback) {
Companies.schema.validate(company);
return super.insert(company, (err, _id) => {
CompaniesProfile.insert({ company_id: _id });
CompaniesSettings.insert({ company_id: _id });
});
}
}
Companies = new CompaniesCollection("companies");
Companies.schema = new SimpleSchema({
ticker: { type: String }
});
Meteor.methods({
"admin.company.add": function(data) {
// Just hide this one, I guess its not releavant
}
});
Meteor.publish("companies", () => {
return Companies.find({});
});
For the server side I have nothing more except my Component CompaniesManager, which is a basic React component, should I import any file concerning my collection ?
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Meteor } from "meteor/meteor";
import { withTracker } from "meteor/react-meteor-data";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import { Row, Col } from "react-flexbox-grid";
Yes, you either have to import it in your client file or you have to define a collection by the same name somewhere on the client and import it to your current file. Otherwise the client won’t have anywhere to store the documents that get published by the server and you won’t have a reverence to the Collection in your components.