我有一个令人沮丧的问题:
Meteor.publish('userBox', function() {
if (Meteor.user()) {
if (UserBox.boxId) {
return UserBox.find({boxId: Meteor.user()._id},
{'balance': 1,
'myGames': 1,
'createdGames': 1
});
} else {
UserBox.insert({boxId: Meteor.user()._id,
balance: 111,
myGames: 7,
createdGames: {}
});
return UserBox.find({boxId: Meteor.user()._id},
{'balance': 1,
'myGames': 1,
'createdGames': 1
});
}
}
});
为什么不起作用?我只想要另一个集合,它会将一些对象提前保留到Meteor.users
,并且我可以为当前用户保留任何其他属性。
答案 0 :(得分:0)
The condition is never true, because Meteor.user()
doesn't work in publish functions:
Meteor.user() Anywhere but publish functions
http://docs.meteor.com/#/full/meteor_user
Use this.userId
instead.
答案 1 :(得分:0)
最后......它很简单...... http://docs.meteor.com/#/full/accounts_oncreateuser