Created
March 2, 2016 03:59
-
-
Save chihirokaasan/2713307fefdbaf27fe2c to your computer and use it in GitHub Desktop.
php mongo seq
This file contains 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 | |
//cakephpチックに書くとこんな感じ? | |
//cakephpでなければ適当にfunctions のところだけ抜き出して使ってください | |
App::uses('AppModel', 'Model'); | |
class Counter extends AppModel { | |
public function connect() { | |
$client = new MongoClient(); | |
$db = $client->selectDB('databaseName'); | |
return $db; | |
} | |
public function seq($collection) { | |
$db = $this->connect(); | |
$seq = $db->command( | |
array('findandmodify' => 'counters', | |
'query' => array('_id' => $collection),//users とかシーケンス振りたいコレクション名とか | |
'update' => array('$inc' => array('seq' => 1)), | |
'new' => TRUE) | |
); | |
return $seq; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment