Skip to content

Instantly share code, notes, and snippets.

@nateabele
Created April 4, 2014 18:28
Show Gist options
  • Save nateabele/9980450 to your computer and use it in GitHub Desktop.
Save nateabele/9980450 to your computer and use it in GitHub Desktop.
<?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