Friday 21 April 2017

Duplicate name feature like file system

I am trying to do something like file system of our computer in which if file name "test" is presented in one folder and we try to create one more file with same name then we get result as "test(01)" and if we try again then we get the result "test(02)".

Basically, I want this kind of feature in my project. I am using mongoose and nodejs

// schema
var schema = new Schema({
    name: {
        type: String,
        required: true
    }
}, options);

Whenever user added name in database i have to check if same name is already present then we append the count in its name.

Like first time user added name = test , then in db we will save as name = test

Second time added name = test, then in db we will save name as name = test(01)

Third time added name = test, then in db we will save name as name = test(02)

and so on like this.

Can anyone suggest help. Thanks !



via Sam

No comments:

Post a Comment