0

我的应用程序同时拥有 facebook 和 twitter 用户。现在用户可以将两个帐户合并在一起,这意味着他们可以使用 facebook 或 twitter 帐户登录。

现在,我有一个这样的模型。


{ "_id" : ObjectId("51103a3e69931d2f03000001"), "email" : "email", "id" : "twitter_id", "token" : "token", "secret" : "secret"}

{ "_id" : ObjectId("51103a3e69931d2f03000001"), "email" : "email", "id" : "facebook_id", "token" : "token", "secret" : ""}

现在,如果这两个帐户相同,并且用户决定将他的帐户之一合并或连接到其他帐户。我应该如何有效地改变这个模型和性能。我正在考虑有另一个对象称为

{"linked_ids" : ["facebook_id", "linkedin_id" ]}

在这两个帐户中。所以,数据应该是这样的。一旦合并。


{ "_id" : ObjectId("51103a3e69931d2f03000001"), "email" : "email", "id" : "twitter_id", "token" : "token", "secret" : "secret", "linked_id" : ["facebook_id"] }

{ "_id" : ObjectId("51103a3e69931d2f03000001"), "email" : "email", "id" : "facebook_id", "token" : "token", "secret" : "", "linked_id" : ["twitter_id"] }

不确定这是否是提高性能和可扩展性的最佳方式?

4

1 回答 1

0

Why not have one user document in a user collection from the start? You could model it this way instead:


{
   "_id" : ObjectId("..."),
   "username" : "bob123",
   "accounts" : [
      {
         "email": "email",
         "id": "twitter_id",
         "token": "token",
         "secret": "secret",
         "type" : "Twitter"
      },
      {
         "email": "email",
         "id": "facebook_id",
         "token": "token",
         "secret": "",
         "type" : "Facebook"
      }
   ]
}

Mongo has plenty of operations to deal with arrays. You can add to them, update one item in the array only, etc.

Doing joins with Mongo introduces complexity that it isn't good at handling as of now. You'd have to do that "join" in your application.

Also this model means you can add any other forms of authentication in one document.

于 2013-02-10T19:47:19.150 回答