Olivier
Olivier

Reputation: 3471

Store/Sync Facebook Graph in a NoSQL (MongoDB)

I'm building an app that needs to be able to extend facebook graph data.

I'm new to NoSQL storage and i'm looking for help.

Using the graph api, i can retreive a user, since i would like my app to be able to extend several social graph providers, i move every specific facebook keys retreived into a facebook array subset.

[User] => Array
    (
        [_id] => 4dd50c139bcb233c0c000000
        [name] => Foo Bar
        [first_name] => Foo 
        [last_name] => Bar
        [username] => fbar
        [location] => Array
            (
                [id] => 110774245616525
                [name] => Paris, France
            )

        [gender] => male
        [email] => [email protected]
        [timezone] => 2
        [locale] => fr_FR
        [facebook] => Array
            (
                [id] => 12345678
                [link] => http://www.facebook.com/foobar
                [verified] => 1
                [updated_time] => 2011-05-16T17:30:23+0000
                [picture] => https://graph.facebook.com/12345678/picture
            )

        [created] => MongoDate Object
            (
                [sec] => 1305807891
                [usec] => 0
            )
    )

Then i grab his friends, and i want to be able to keep them in sync with my database. I don't know if i should register each friend as separate users and try to use references, or if i can just add a Friend subset.

I read : http://www.mongodb.org/display/DOCS/Trees+in+MongoDB which is quite helpfull... But i'm still unsure what i should do.

Thanks a lot.

Upvotes: 5

Views: 2591

Answers (4)

Lvca
Lvca

Reputation: 9049

To store a graph like your you should use a GraphDB, not a DocumentDB. Try OrientDB: it's a document-graph nosql with all the best feature of both worlds. The most important feature for your use case is the ability to traverse thousands of relationships in few ms! Open Source and Apache 2 licensed.

Upvotes: 1

Gates VP
Gates VP

Reputation: 45307

This is a question of "embed vs. reference".

Here's one good reply on SO.

Here are the official docs on schema design. They're a good place to start looking at these questions.

Upvotes: 3

frail
frail

Reputation: 4128

I had a similar application and I stored friends as an other user. But be sure that you have a flag that indicates if that user is an application user or not, or the data would be somehow chaotic at some point.

for user:

{
  fbid: xxxx,
  name : "xxxxx",
  ......
  friends : [ xxxx, xxxx, xxxx ],
  is_app_user : true
}

for each friend (who are not application user) :

{
  fbid: xxxx,
  name : "xxxxx",
  is_app_user : false
}

and when they also login you can make is_app_user : true for them aswell.

PS: dont forget to put unique index on fbid

Upvotes: 4

user2665694
user2665694

Reputation:

http://www.mongodb.org/display/DOCS/Trees+in+MongoDB

In addition: if you want to store a graph then use a GraphDB - MongoDB is unlikely the right choice for storing graphs in general...for every task the right tool.

Upvotes: 0

Related Questions