@@ -180,6 +180,7 @@ Sequence.prototype._createCounterModel = function() {
180
180
* @method _setHooks
181
181
*/
182
182
Sequence . prototype . _setHooks = function ( ) {
183
+ var _this = this ;
183
184
184
185
this . _schema . pre ( 'save' , true , ( function ( sequence ) {
185
186
return function ( next , done ) {
@@ -208,7 +209,7 @@ Sequence.prototype._setHooks = function() {
208
209
if ( obj ) return next ( ) ;
209
210
else {
210
211
referenceValue = _this . _getCounterReferenceField ( _thisquery . _update ) ;
211
- _this . _setNextCounter ( _this . _options . reference_fields , referenceValue , function ( err , seq ) {
212
+ _this . _setNextCounterByReference ( _this . _options . reference_fields , referenceValue , function ( err , seq ) {
212
213
if ( err ) return next ( ) ;
213
214
_thisquery . _update [ '$setOnInsert' ] = _thisquery . _update [ '$setOnInsert' ] || { } ;
214
215
_thisquery . _update [ '$setOnInsert' ] [ _this . _options . inc_field ] = seq ;
@@ -232,7 +233,7 @@ Sequence.prototype._setHooks = function() {
232
233
if ( obj ) return next ( ) ;
233
234
else {
234
235
referenceValue = _this . _getCounterReferenceField ( _thisquery . _update ) ;
235
- _this . _setNextCounter ( _this . _options . reference_fields , referenceValue , function ( err , seq ) {
236
+ _this . _setNextCounterByReference ( _this . _options . reference_fields , referenceValue , function ( err , seq ) {
236
237
if ( err ) return next ( ) ;
237
238
_thisquery . _update [ '$setOnInsert' ] = _thisquery . _update [ '$setOnInsert' ] || { } ;
238
239
_thisquery . _update [ '$setOnInsert' ] [ _this . _options . inc_field ] = seq ;
@@ -283,6 +284,10 @@ Sequence.prototype._setMethods = function() {
283
284
Sequence . prototype . _setNextCounter = function ( doc , callback ) {
284
285
var id = this . getId ( ) ;
285
286
var referenceValue = this . _getCounterReferenceField ( doc ) ;
287
+ this . _setNextCounterByReference ( id , referenceValue , callback ) ;
288
+ } ;
289
+
290
+ Sequence . prototype . _setNextCounterByReference = function ( id , referenceValue , callback ) {
286
291
this . _counterModel . findOneAndUpdate (
287
292
{ id : id , reference_value : referenceValue } ,
288
293
{ $inc : { seq : 1 } } ,
0 commit comments