Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongoose 对象中的猫鼬搜索_Mongoose_Schema - Fatal编程技术网

Mongoose 对象中的猫鼬搜索

Mongoose 对象中的猫鼬搜索,mongoose,schema,Mongoose,Schema,我正试图在我的前端建立一个搜索栏。我希望这个搜索栏在一个对象中循环,如果它找到匹配项,则返回找到的值 基本上我有: theSchema.find({ $and: [ { company: String(company)}, { user: String(user) }, { $or: [ {

我正试图在我的前端建立一个搜索栏。我希望这个搜索栏在一个对象中循环,如果它找到匹配项,则返回找到的值

基本上我有:

theSchema.find({
            $and: [
                { company: String(company)},
                { user: String(user) },
                {
                    $or: [
                        { 'information.field1': { $regex: String(search), $options: "i" } },
                        { 'information.field2': { $regex: String(search), $options: "i" } },
                        { 'information.field3': { $regex: String(search), $options: "i" } },
                        { 'information.field4': { $regex: String(search), $options: "i" } },
                    ]
                }
            ]
        })
.then(result => result)
这是我的模式:

const theSchema = new Schema({
    ...
    information: {
        type: Schema.Types.Mixed,
        default: {}
    },
    ...

})
因此,我试图循环遍历我的
信息
对象并搜索其中的所有字段

由于明显的原因,我目前所拥有的有点不切实际。我不希望每次向对象添加新字段时都修改搜索,并且模式中并非所有文档都包含所有字段

我试着在
操作符中查看
$in,但这似乎对数组有效


有没有办法搜索对象中的所有字段?

在这种情况下,可能需要使用聚合在这种情况下,可能需要使用聚合