简体   繁体   English

在服务器启动时从mongodb获取用户文档

[英]get user document from mongodb on server startup

This Meteor server code needs to get a user document at start up. 此Meteor服务器代码需要在启动时获取用户文档。

//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 TypeError:无法读取未定义的属性“ find”

Any idea how to get a user document on server start up? 知道如何在服务器上启动用户文档吗?

TypeError: Cannot read property 'find' of undefined TypeError:无法读取未定义的属性“ find”

means that the variable before find is undefined. 表示find之前的变量未定义。 In this case, the undefined variable is Meteor.users 在这种情况下,未定义的变量是Meteor.users

This is defined in meteor's accounts-base package as documented here . 这是在流星的定义accounts-base包作为记录在这里 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. 当您添加accounts-password它也添加了基于accounts-base因为它是一个依赖项,在此之后, Meteor.users存在(已定义),您的代码将按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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