[英]Mongo DB - Why my Users.findOne is Undefined?
對於有相同問題的新用戶,我將保留此問題的答案。
如果您使用的是autopublish
包,則應注意,它會為每個集合發布.find()
的結果。
但是,默認情況下, Meteor.users.find()
將僅返回_id
和profile
字段,因此Meteor.users
客戶端集合中的文檔將僅具有這兩個字段。
最簡單的解決方法是創建自己的發布(例如allUsers
),並在其中返回所需的字段:
服務器:
Meteor.publish('allUsers', () => {
// check for Meteor.userId() is omitted, put it here, if needed
return Meteor.users.find({}, { fields: { ... } });
});
不要忘記訂閱它:
客戶:
Meteor.subscribe('allUsers');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.