Last active
October 27, 2020 06:31
-
-
Save debojitkakoti/9565409 to your computer and use it in GitHub Desktop.
Revisions
-
debojitkakoti revised this gist
Apr 1, 2014 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,14 +3,14 @@ // select a database $db = $m->seq; // select a collection (analogous to a relational database's table) $collection = $db->counters; $user_collection = $db->user; /******************Function to auto increment seq******************/ function getNextSequence($name){ global $collection; @@ -24,7 +24,8 @@ function getNextSequence($name){ ); return $retval['seq']; } /********************Example Usage**********************************/ $db_array=array('_id' => getNextSequence("userid"), 'name' => 'debojit'); $user_collection->insert($db_array); -
debojitkakoti created this gist
Mar 15, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ <?php $m = new MongoClient(); // select a database $db = $m->seq; // select a collection (analogous to a relational database's table) $collection = $db->counters; $user_collection = $db->user; /**********Function to auto increment seq************/ function getNextSequence($name){ global $collection; $retval = $collection->findAndModify( array('_id' => $name), array('$inc' => array("seq" => 1)), null, array( "new" => true, ) ); return $retval['seq']; } $db_array=array('_id' => getNextSequence("userid"), 'name' => 'debojit'); $user_collection->insert($db_array);