As a quick followup to the last blog, I was asked to demonstrate how we could include some metadata with a file during or after upload.
This is a great feature since we can retrieve all the information attached with a document during a query. Including metadata (i.e. comments, dates, votes or WHATEVER ELSE YOU LIKE) is just as easy.
We are going to pick up the ball at the point where you’ve got all your MongoDB objects ready:
<?php $date = new MongoDate(); //Use $set to add metadata to a file $metaData = array('$set' => array(“comment”=>”MongoDB is awesome”, “date”=>$date)); //Just setting up search criteria $criteria = array('_id' => $id); //Update the document with the new info $db->grid->update($criteria, $metaData); ?>
Did you break a sweat? Probably not.
BTW, I threw in a little extra tidbit there with MongoDate(). It’s a better way of inputting a date into Mongo instead of using PHP date with a bunch of formatting to get it just right.