mongodbfacebookfacebook-graph-apinosql

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] => fbar@gmail.com
        [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.


Solution

  • 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