[SOLVED] Collection.find().fetch() returns []

Hello. I’ve got a meteor project with react and flow router but there is a problem with the database: if I do a console.log(collection.find().fetch()) returns []. I removed autopublish so I publish my collection in the lib/collection.js file that I import in the server/main.js and I subscribe to it using FlowRouter in lib/routes.js that is imported in client/main.js:

console.log(“Publishing ‘Projects’ collection”);
Meteor.publish(‘Projects’, () => {
return Projects.find();
FlowRouter.route(’/’, {
name: ‘home’,
subscriptions() {
console.log(“Subscribing to ‘Projects’ collection”)
this.register(‘Projects’, Meteor.subscribe(‘Projects’));
action() {
mount(MainLayout, {content: , })

What is the problem?

In general, it is not recommended to run subscriptions on the router level in FlowRouter. Your code looks ok, though. But you don’t provide the code of the actual template calling the collection.find(). I guess the problem lies there.

Oh okay. The collection.find is in the action() in the router:
The ProjectsComponent has a propTypes called projects of type PropTypes.array
if it’s not recommended to run the subscriptions in FlowRouter, where should I run it?

I had the same problem ! Try this link
Hopefully this helps you :slight_smile:

Thank you this helped a lot. Now I subscribe in FlowRouter in action() using the tracker and it works :slight_smile: but using a form in the same page, it doesn’t automatically update. Why is that?

FlowRouter isn’t reactive so when something changes, FlowRouter doesn’t update the view.

You should read through the Meteor Guide, especially the react chapter.

How should I do it then? Where should I subscribe to the collection so that it’s reactive?

Read the meteor guide. Everything you need to know is in there.

Thank you :slight_smile: I’ve read again the meteor guide and I finally understood. I now have a createContainer. That’s where I subscribe to my collection that I return to my component