Last active
December 16, 2015 05:09
-
-
Save patsToms/5382468 to your computer and use it in GitHub Desktop.
Update MongoDB document using Monga
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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