meteor - 从服务器端获取价值

flo*_*wen 2 meteor

我想从current_user(客户端)向userY(成员)发送电子邮件,而不会将emailaddress暴露给客户端.所以所有服务器端.

我有userY的_id(来自路由器参数:email.toUser = Router.current().params._id;)并将其作为值发送给方法.

在方法函数中我想做类似的事情

var to = Meteor.users.find({ _id: email.toUser }); 
Run Code Online (Sandbox Code Playgroud)

现在,当我调试console.log(to)时,我得到一个巨大的_mongo对象而不是用户配置文件(我希望能够记录:to.profile.email)从电子邮件字段中获取值的最佳方法是什么?

Sal*_*ter 5

你看到的是光标到集合集.

要检索记录,您可以使用 .fetch()

var to = Meteor.users.find({ _id: email.toUser }).fetch();
console.log(to[0].profile.email);
Run Code Online (Sandbox Code Playgroud)

当您按ID查找时,您只需要1个结果,因此您也可以使用findOne()而不是find()直接返回第一个元素.

var to = Meteor.users.findOne({ _id: email.toUser });
console.log(to.profile.email);
Run Code Online (Sandbox Code Playgroud)

编辑:我想补充一点,替代{ _id: email.toUser }通过email.toUser应该工作.仅使用ID时,无需传递对象.