Skip to content

Instantly share code, notes, and snippets.

@patsToms
Last active December 16, 2015 05:09
Show Gist options
  • Select an option

  • Save patsToms/5382468 to your computer and use it in GitHub Desktop.

Select an option

Save patsToms/5382468 to your computer and use it in GitHub Desktop.
Update MongoDB document using Monga
<?php
/*
* as from - https://github.com/FrenkyNet/Monga
*/
$connection = Monga::connection($dns, $connectionOptions);
$database = $connection->database('db_name');
$collection = $database->collection('collection_name');
//one way to get your document
$frank = $collection->findOne(function($query){
$query->where('name', 'Frank')
->whereLike('surname', '%e Jo%');
});
//here another
$frank = $collection->find(array('name' => 'Frank', 'surname' => new MongoRegex('/e Jo/imxsu')));
//make some changes to Frank's age
$frank['age']++;
//here is your update ^_^
$collection->save($frank);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment