Friday, 26 May 2017

String + autoincrement number on mongoose

I want to create a String + number every time a value is inserted on database (the number must be autoincrement). Is it possible to do in Schema? Or do I need to do that before the value's inserted on database?

'question' -> String followed by an autoincrement number

    var random = [{
        question: 'question1'
    },{
        question: 'question2'
    },{
        question: 'question3'
    },{
        question: 'question4'
    }];

    const RandomSchema = new Schema({
        question: {
            type: String,
            unique: true
        }
    })



via carlos