Created
April 4, 2014 18:28
-
-
Save nateabele/9980450 to your computer and use it in GitHub Desktop.
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 characters
<?php | |
/* ... */ | |
/** | |
* Allows each Mongo collection to have a sequence ID for numbering objects. | |
* | |
* @param array $scope The scope for this counter. A scope is an array of key/value pairs | |
* that represent the conditions used to group this sequence. For example, a | |
* scope may be the ID of a company, allowing each company to have their own | |
* unique sequence. | |
*/ | |
static public function seq(array $scope = []) { | |
$seq = static::connection()->connection->command([ | |
'findandmodify' => 'seq', | |
'query' => ['source' => static::meta('source')] + $scope, | |
'update' => ['$inc' => ['seq' => 1]], | |
'upsert' => true, | |
'new' => true | |
]); | |
return $seq['value']['seq']; | |
} | |
/* ... */ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment