Skip to content

Instantly share code, notes, and snippets.

@chihirokaasan
Created March 2, 2016 04:13
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/0b645b2735389b620999 to your computer and use it in GitHub Desktop.
Save chihirokaasan/0b645b2735389b620999 to your computer and use it in GitHub Desktop.
Insert mongo with AutoIncrement
$itemid = $this->Counter->seq('itemid');
$itemArray = [ "_id" => $itemid['value']['seq'],
"title" => 'hogehoge',
"user_id" => 1,
"created" => date('Y-m-d H:i:j'),
];
function add($itemArray) {
$client = new MongoClient();
$db = $client->selectDB('databaseName');
$col = $db->selectCollection('item');
$col->insert( $itemArray );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment