流星/MongoDB是否有可用的字段可供发布? [英] Meteor/MongoDB see available fields for publish?

查看:68
本文介绍了流星/MongoDB是否有可用的字段可供发布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查看用户集中哪些字段可供我从服务器发布并从客户端订阅?我正在使用Meteor.JS的Google Auth函数,但是我正在使用它们对YouTube进行授权,因此这些字段不是标准的或没有记录的.

How can I see what fields are in the users collection that are available for me to publish from the server and subscribe to from the client? I'm using Meteor.JS's Google Auth functions, but I'm using them to authorize YouTube so the fields aren't standard or documented.

登录代码:

Meteor.loginWithGoogle({
    requestPermissions: ['profile', 'email', 'https://www.googleapis.com/auth/yt-analytics.readonly', 'https://www.googleapis.com/auth/youtube']
});

推荐答案

您可以检查服务器上Meteor.users中的记录,例如,将它们记录到控制台中.例如,在server.js中:

You can inspect records in Meteor.users on the server, for instance by logging them to the console. For example, in server.js:

Meteor.startup(function() {

  Meteor.publish("nothing", function() { 
    if (this.userId)
      console.log(Meteor.users.findOne({_id: this.userId}));
  });

});

然后在客户端中订阅:

Meteor.subscribe("nothing");

这会将登录用户的内容记录到服务器控制台(终端窗口).它在发布方法中的原因是Meteor不允许在方法外部访问当前用户,因此我将其命名为"nothing"以表示它不执行任何操作,仅用于临时检查.

This will log the contents of the logged in user to the server console (terminal window). The reason it's in a publish method is that Meteor doesn't allow accessing the current user outside a method, so I named it "nothing" to indicate that it doesn't do anything and is just for temporary inspection purposes.

这篇关于流星/MongoDB是否有可用的字段可供发布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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