Mongodb 如何在mongoose模型中创建多个自定义索引
我有这样一个模式:Mongodb 如何在mongoose模型中创建多个自定义索引,mongodb,indexing,mongoose-schema,Mongodb,Indexing,Mongoose Schema,我有这样一个模式: const positionSchema = new Schema({ positionType: { type: String, enum: [ 'USER', 'ADMIN', 'DEFAULT', 'SYSTEM_DEFAULT', ], default: positionEnum.USER, }, title: String, comapny:company: { ty
const positionSchema = new Schema({
positionType: {
type: String,
enum: [
'USER',
'ADMIN',
'DEFAULT',
'SYSTEM_DEFAULT',
],
default: positionEnum.USER,
},
title: String,
comapny:company: { type: Schema.Types.ObjectId, ref:'companies' },
})
我想在此架构上定义索引
positionSchema.index({title: 1,company: 1},{unique: true})
但我想在这个指数上增加一些限制。当positionType(用户和管理员)唯一时
当positionType(默认值和系统默认值)唯一时。
为了澄清,我举了一些例子