如何向 Meteor.users 集合添加字段 [英] How to add fields to the Meteor.users collection

查看:67
本文介绍了如何向 Meteor.users 集合添加字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要存储在客户端上我的用户文档中的 Facebook accessToken.按照流星文档,我应该添加一个新的发布调用.

I want the Facebook accessToken that is stored in my user's document on the client. Following the meteor documentation, I should just add a new publish call.

在 server.js 中:

Meteor.publish("access_token", function () {
  return Meteor.users().find(
    { _id : Meteor.userId() }, 
    {'services.facebook.accessToken': 1}
  );
});

在 client.js 中:

Meteor.subscribe("access_token");

好吧,这就是我迷路的地方.现在访问令牌是否应该只出现在 Meteor.users 集合中供登录用户使用?喜欢:

Alright, here's where I get lost. Should the accessToken just show up in the Meteor.users collection now for the logged in user? Like:

var user = Meteor.users.findOne({ _id : Meteor.userId() }); 
console.log(user); // includes services.facebook.accessToken now

显然,我已经尝试了上述方法,但没有显示 accessToken.是的,我已经确认 mongo 文档包含 services.facebook.

Obviously, I've tried the above and the accessToken doesn't show up. Yes, I've confirmed that the mongo document contains services.facebook.

那么...我是否创建一个新的客户端集合并以某种方式将其连接到新的发布?我如何获得 accessToken?

So... do I create a new client collection and somehow hook it up to the new publish? How do I get the accessToken?

推荐答案

你应该使用fields"关键字

you should use "fields" keyword

Meteor.users.find({ _id: this.userId },
    { fields: { the-extra-fields-that-you-want-go-here: 1 } }
);

http://docs.meteor.com/#fieldspecifiers

这篇关于如何向 Meteor.users 集合添加字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆