Ok I am making a blog system using MongoDB as the back end. I want to do the same thing as wordpress when you edit it saves the past versions and allows you to revert to them if needed.
I would like to do the same.
I have a few ways to doing it. but un sure if this is the best easiest way to do it and would like some suggestions.
the first is a find and the insert $SET
<?php
$cursor = $collection->find(array("_id"=> new MongoId($data)));
if ($cursor->count() > 0)
{
while( $cursor->hasNext() ) {
foreach($cursor->getNext() as $key => $value)
{
define("_".strtoupper($key), $value);
}
}
$cursor = $collection->update(array("_id" => new MongoId($data)),
'$set'=>array("title"=>$data['TITLE'], "content"=>$data['content'], "past_versons"=>array("title" => _TITLE, "content" => _CONTENT)));
}
?>
So my question is this the way I would do it.
here a sample JSON
{
"title":"blog title",
"content":"blog content",
"past_verson":[{"title":"blog title past","content":"past blog content"}]
}