Created
March 2, 2016 04:13
-
-
Save chihirokaasan/0b645b2735389b620999 to your computer and use it in GitHub Desktop.
Insert mongo with AutoIncrement
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
$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