我正在研究 Meteor,试图从 Mongodb 集合中找到一些值。 这是代码:
var sameLogins = Users.findOne({login: 'a'});
console.log(sameLogins);
那么,有人能告诉我我错过了什么吗?
我正在寻找发布/订阅的内容,但我正在使用自动发布模块。
谢谢!
最佳答案
我会将这个问题的答案留给有同样问题的新用户。
如果您使用 autopublish
包,那么您应该知道它正在为每个集合发布 .find()
的结果。
但是,默认情况下,Meteor.users.find()
将仅返回 _id
和 profile
字段,因此您的 中的文档code>Meteor.users
client 集合将仅包含这两个字段。
最简单的解决方法是创建您自己的出版物(例如 allUsers
)并在其中返回您需要的字段:
服务器:
Meteor.publish('allUsers', () => {
// check for Meteor.userId() is omitted, put it here, if needed
return Meteor.users.find({}, { fields: { ... } });
});
不要忘记订阅它:
客户:
Meteor.subscribe('allUsers');
关于javascript - Mongodb - 为什么我的 Users.findOne 未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45943810/