Skip to content

Instantly share code, notes, and snippets.

@chihirokaasan
Created March 2, 2016 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chihirokaasan/2713307fefdbaf27fe2c to your computer and use it in GitHub Desktop.
Save chihirokaasan/2713307fefdbaf27fe2c to your computer and use it in GitHub Desktop.
php mongo seq
<?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