dimanche 9 septembre 2012

Versioning with MongoDB

For storing history of changes to a record, we can use this kind of structure :

address:


{
    _id : "id of address book record",
    "city" : "San Francisco", 
    "state" : "California"
}




history_address:

{
    _id : "id of history address book record",
    changes : { 
                1234567 : { "city" : "Omaha", "state" : "Nebraska" },
                1234568 : { "city" : "Kansas City", "state" : "Missouri" }
               }
}



1234567 and 1234568 are timestamps.

And this is the query for storing history :
db.history_address.update({_id: ID}, {$set : { changes.12345 : CHANGES } }, true);


More details here :
http://stackoverflow.com/questions/4185105/ways-to-implement-data-versioning-in-mongodb

Aucun commentaire:

Categories