简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM