定义Schema如下: sender : {type: mongoose.Schema.Types.ObjectId, ref: ‘user’}, //发送人id receivers : [{type: mongoose.Schema.Types.ObjectId, ref: ‘user’}], //收件人id copiers : [{type: mongoose.Schema.Types.ObjectId, ref: ‘user’}], //抄送人id 数组 title : {type: String, default: ‘’}, content : {type: String, default: ‘’}, //邮件内容 html字符串 files : [{type: mongoose.Schema.Types.ObjectId, ref: ‘files’, default: ‘’}], //附件url地址 数组 这是个邮件部分的Schema,现在要对其做模糊搜索,发现用了ObjectId 没法搜索,,, 想法大概是这样写搜索的,虽然肯定是错的: await EmailModel.find({ $or: [ {sender.nickname: new RegExp(searchValue)}, {receivers.nickname: new RegExp(searchValue)}, {copiers.nickname: new RegExp(searchValue)}, ] }).populate([ {path: ‘sender’, select: ‘nickname’}, {path: ‘receivers’, select: ‘nickname’}, {path: ‘copiers’, select: ‘nickname’}, {path: ‘files’} ])…execAsync(); 请问下大神们,这种情况该怎么处理?
只能查两次,先查符合条件的用户的objectid再用这个列表去筛选邮件