【发布时间】:2014-05-13 01:57:05
【问题描述】:
我需要在流星的用户集合中添加一个附加字段。所以我正在做的是在下面的 server.js 文件中添加以下代码。
//server.js
Meteor.publish("users", function () {
if (this.userId) {
return Meteor.users.find({_id: this.userId},
{fields: {'notified': 1}});
} else {
this.ready();
}
});
client.js如下:
// client.js
Deps.autorun(function() {
Meteor.subscribe('users');
});
为了在新用户登录时添加字段,fixture.js 如下:
// fixture.js
Accounts.onCreateUser(function (options, user) {
if (options.profile) {
user.profile = options.profile;
user.profile.notified = false;
}
return user;
});
在代码中,我正在像这样更新通知字段
// inside a loop taking all the users of the collection
// where myUsers is the loop index.
Meteor.users.update(myUsers._id, {$addToSet: {notified : 1}});
但令我惊讶的是,当我通过 mongo 控制台或浏览器控制台检查该字段是否已添加到集合中时,它没有显示出来。为什么这样?。我已经阅读了网上几乎所有可用的文章并关注了http://docs.meteor.com/#meteor_users,但仍然无法正常工作。那么,有谁知道应该怎么做?我一无所知。
【问题讨论】:
-
Meteor.users.update(myUsers._id, {$addToSet: {notified : 1}});更新发生在服务器还是客户端?
标签: javascript mongodb meteor