Meteor.js - 更新用户个人资料最方便的方法是什么?

标签 meteor

我发现我广泛使用用户配置文件。我希望能够做这样的事情:

Meteor.user().profile.some_setting = 'something';
Meteor.user().update();

更新用户个人资料最方便的方法是什么?

最佳答案

Meteor.user() 是一个文档,而不是一个游标。它实际上是 Meteor.users.findOne(this.userId) 的别名。

您可以通过方法调用(服务器)或直接在客户端上执行此操作。

方法调用方式:

//server code
Meteor.methods({
  updateProfile : function(newProfile) {
    if(this.userId)
      Meteor.users.update(this.userId, {$set : { profile : newProfile }});
  }
});

在客户端:

Meteor.call('updateProfile', myNewProfile);

我建议通过服务器方法来执行此操作,因为代码在更干净的环境中运行。

如果您想直接在客户端上执行此操作:

Meteor.users.update(Meteor.userId(), {$set : {profile : myNewProfile}});

(Meteor.userId()Meteor.user()._id 的别名)
More infos on the doc!

关于Meteor.js - 更新用户个人资料最方便的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26933335/

相关文章:

Meteor.publish 不是一个函数

javascript - Meteor JS 中的负载 Controller

javascript - 如何为两个 ddp 连接的应用程序使用相同的数据库

javascript - Iron-router(最新)在 Windows 7 x64 (Meteor 0.8.3) 上的安装问题

javascript - 如何使用 Meteor Iron Router 创建单独的 HTML 模板文件

javascript - 如果本地字段存在于外部字段中则聚合

logging - 本地开发模式下的 meteor 日志保存在哪里?

authentication - 以另一个用户身份访问 Meteor 应用程序

javascript - 单击事件更改复杂的 SVG (Meteor)

google-maps-api-3 - meteor 模板中包含的谷歌地图被渲染两次