Meteor facebook id 与帐户 id

Meteor facebook id vs accounts id

我正在制作一个同时使用帐户包和 facebook 图表的应用程序 api。特别是朋友 api。好友 api returns 所有使用过该应用程序的 facebook 好友。问题是它 returns facebook id,并且帐户包生成应用程序特定的 id。当我想从包含朋友信息但存储有应用程序特定 ID 的集合中检索信息时,这是有问题的。我通过将 fb id 和帐户 id 存储在集合中来解决这个问题。

但我仍然无法根据他们的 fb id 更新用户数据,因为只允许使用应用程序特定的 id 进行更新。我想要的,但不允许:

UserData.update({fbId: friend.fbId},{$push: {some: data}});

我能想到的唯一解决方案是先获取每个用户 ID,如下所示:

var friendId = UserData.findOne({fbId: friend.fbId})._id;

这显然不是一个好的解决方案,因为每次更新都需要一个额外的数据库调用。

有没有办法在创建时将帐户 ID 设置为等于 Facebook ID?或者你有什么其他的建议。

扩展上面的评论:

MoeRum: @Xinzz UserData is a custom collection. If try updating with fbId I get the following error: Uncaught Error: Not permitted. Untrusted code may only update documents by ID. [403]

那是因为您正在尝试在客户端进行更新。您只能在客户端通过 ID 更新。只要您在服务器上执行,您尝试执行的操作应该不是问题。

来自 Meteor 文档(更多参考:http://docs.meteor.com/#/full/update):

The behavior of update differs depending on whether it is called by trusted or untrusted code. Trusted code includes server code and method code. Untrusted code includes client-side code such as event handlers and a browser's JavaScript console.

  • Trusted code can modify multiple documents at once by setting multi to true, and can use an arbitrary Mongo selector to find the documents to modify. It bypasses any access control rules set up by allow and deny. The number of affected documents will be returned from the update call if you don't pass a callback.

  • Untrusted code can only modify a single document at once, specified by its _id. The modification is allowed only after checking any applicable allow and deny rules. The number of affected documents will be returned to the callback. Untrusted code cannot perform upserts, except in insecure mode.