'use strict'
/**
 * Sequence model (Start from 0)
 * @param mongoose
 * @author CodeHz
 * @returns {Model|*}
 */
module.exports = function (mongoose) {
    let Schema = mongoose.Schema;
    let sequenceSchema = new Schema({
        _id: { type: String, required: true, index: true },
        seq: { type: Number, default: -1 }
    });

    /**
     * Get next document id of collection
     * @param name Collection name
     * @param cb
     */
    sequenceSchema.statics.getNextSequence = (name, cb) => {
        mongoose.model('Seqs').findOneAndUpdate({ _id: name },
            { $inc: { seq: 1 } },
            { upsert: true },
            (err, idDoc) => cb && cb(err, idDoc.seq));
    };
    
    sequenceSchema.statics.SequenceRollback = (name, cb) => {
        mongoose.model('Seqs').findOneAndUpdate({ _id: name },
            { $inc: { seq: -1 } },
            { upsert: true },
            (err, idDoc) => cb && cb(err, idDoc.seq));
    };

    return mongoose.model('Seqs', sequenceSchema);
}
@@ -315,18 +315,17 @@
 efault: 
--1
+0
  %7D%0A    %7D
@@ -669,32 +669,36 @@
 b(err, idDoc.seq
+ - 1
 ));%0A    %7D;%0A    %0A
@@ -927,27 +927,16 @@
 & cb(err
-, idDoc.seq
 ));%0A    

change seq gen