Noob Question: Client not able to read server-side MongoDB?

Hello, so I am working on learning Meteor with the “Your First Meteor Application” book and I because its a bit outdated already, it does not take into account the, what I assume is new environment set up of having a certain folder & files for server and another for client side things. Now, I made it to the part where I just create my Mongo database with the line ‘PlayerList = new Mongo.Collection(‘players’);’ and that works fine in the client main.js. But just for testing purposes I opened up a new tab and went to the server and tried to access the ‘documents’ I successfully added on one tab to see if it persisted, and nope, on the new tab the DB is empty. So I attempted to put the same code in the server-side main.js, but now the client/DOM is putting out this error: ‘Uncaught ReferenceError: PlayerList is not defined(…)’.

I was wondering how I should go about fixing this or what practices I should be using in this case? Any help would be great, thanks in advance :slight_smile:

I recently read “Your First Meteor Application” and “Your Second Meteor Application” and examples used by author are up to date. I didn’t had any difficulty.

Well I mean it was released almost a year ago, and for Meteor it seems like that’s a lifetime. It does appear to be outdated in the sense that it does not take into account the way Meteor now has its client and server environments set up, which only appears to be an issue if you try to do something as simple as open the app again in a different tab.

bump :frowning: Still haven’t found a solution yet :confused:

When you say you put the same code on the server, do you mean this line?

The code you found in those tutorial will still work. The client/ and server/ folders you mention have always been there and worked in the same way they do today.

Meteor 1.3 does bring some new functionality and new folders, but if you want to follow those tutorials as they are written you’ll be fine.

However, if you have split your code already into client/ and server/ folders then the easiest way to proceed is to create a new folder for code to be run on client and server. Traditionally, this has been lib/. In there you would add a .js file containing PlayerList = new Mongo.Collection('players'); and remove from any other files where you may have it.

You should then be good to go.

1 Like