0

I am working on Mongo and i need to maintain Unique value in field so i done filed as unique but if i submit the the error will be null .

Here is my code .

var RepositorySchema = new mongoose.Schema({
    folderName: { type: String, unique: true},
    tag: String ,
    ismainFolder: { type: Boolean },
    innerFiles:  [{filename : String,  isFolder: { type: Boolean }, parentfolderId: { type: Schema.ObjectId, ref: 'repository' }, filelocation: { type: String } }],
    innerFolder: [{foldername: {type : String, unique: true}, ismainFolder: { type: Boolean }, parentfolderId: { type: Schema.ObjectId, ref: 'repository' } }],
});

For innerFolder {foldername: {type : String, unique: true} is not working .

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • An error of null generally means there was no error. – Scimonster Aug 11 '17 at 06:56
  • This is what happens when you do not mark a `"unique"` constraint which creates a "unique" index with `required: true`. If you mean it to be "unique" then you mean it to be `required`. Or remove the `"unique"`. You cannot have it both ways. – Neil Lunn Aug 11 '17 at 06:58

0 Answers0