Fred J. Fred J. - 28 days ago 10
Javascript Question

get user document from mongodb on server startup

This Meteor server code needs to get a user document at start up.



//server.js
let curs = Meteor.users.find({'name':'jack'});


Meteor is fired from the commend line like this:

MONGO_URL="mongodb://username:password@host" meteor --port 7001


Which gives the error:


TypeError: Cannot read property 'find' of undefined


Any idea how to get a user document on server start up?

Answer

TypeError: Cannot read property 'find' of undefined

means that the variable before find is undefined. In this case, the undefined variable is Meteor.users

This is defined in meteor's accounts-base package as documented here. When you added accounts-password it also added accounts-base as it is a dependency, and after that Meteor.users exists (is defined) and your code will work as you expect.

Comments