我正在使用Mongo,我需要在字段中保持唯一值,所以我完成了唯一的归档,但如果我提交错误将为null。
这是我的代码。
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' } }],
});
对于innerFolder {foldername:{type:String,unique:true}不起作用。