Is importing & sharing a collection in client necessary? Error

Hi, I’m using meteor with React Native and I’m encountering some issues with subscribing and getting data from my collection

Basically my current set up is I have 2 folders, one called App and one called Backend. App is the react native application and Backend is the meteor server and admin client.

In my meteor server I have a collection.js with the following:

import { Mongo } from 'meteor/mongo';

export const Tasks = new Mongo.Collection('tasks');

And my publish on the backend is:

import { Tasks } from '../imports/collections.js'

Meteor.publish("newTask", function () {
  return Tasks.find();

Then in my react native app I have

export default withTracker((props) => {
    return {
        newTaskReady: Meteor.subscribe('newTask').ready(),
        task: Tasks.find(),

Is it wise to Import Tasks from a collection that is in a complete separate folder on my desktop? Im getting errors when I try “…/…/App/imports/collections.js” saying it doesnt exist

Is there any other way of doing this than importing from a complete different folder? If not, how can I fix this

As far as I can tell the .ready() subcription works, its just the find() that doesnt

Could I just make a new collections.js and put it in the react native app, or it must be imported from the meteor app?

Short answer: Yes, it is necessary

Long answer:
Not necessarily the same file

Subscriptions will fill a collection with the same name on the client with the data published.
So as long as there is a new Mongo.Collection('tasks') call on both client and server, the subscription can place the data into that client-side collection.

The easiest way to see this in action is to add const Tasks = new Mongo.Collection('tasks') in your app and you’ll see that the .find() now works without needing to import the collection file

1 Like