Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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
MongoDB嵌套搜索,项目部分结果_Mongodb_Mongoose_Mongodb Query_Aggregation Framework - Fatal编程技术网

MongoDB嵌套搜索,项目部分结果

MongoDB嵌套搜索,项目部分结果,mongodb,mongoose,mongodb-query,aggregation-framework,Mongodb,Mongoose,Mongodb Query,Aggregation Framework,我有一个这样的模型,基于其他多个SO问题的建议,以数组形式使用多种语言: Exercise Schema ---------------- [{ _id: "5f626ca1fcfe0005857e823f", Image: "image url", ...ExtraDetails, Translations: [ { _id: "5f626ca2fcfe0005857e870b&

我有一个这样的模型,基于其他多个SO问题的建议,以数组形式使用多种语言:

Exercise Schema
----------------
[{
    _id: "5f626ca1fcfe0005857e823f",
    Image: "image url",
    ...ExtraDetails,
    Translations: [
       {
          _id: "5f626ca2fcfe0005857e870b",
          Language: "en",
          Name": "Push Ups"
       },
       {
          _id: "5f626ca2fcfe0005857e870c",
          Language: "no",
          Name: "Armhevinger"
       }
    ]
},
{
    _id: "5f626ca1fcfe0005857e82c9",
    Image: "image url",
    ...ExtraDetails,
    Translations: [
       {
          _id: "5f626ca2fcfe0005857e8795",
          Language: "en",
          Name": "Weighted Push Ups"
       },
       {
          _id: "5f626ca2fcfe0005857e8796",
          Language: "no",
          Name: "Armhevinger med vekt"
       }
    ]
}]
我已将此索引添加到数据库中:

db.exercises.createIndex({ "Translations.Name": "text" });
我现在想做的是,根据语言参数查询并返回,然后由用户搜索,只包含一些字段。让我举一个例子:

Language=“en” Search=“推送”

我想把这个还给你:

[{
    _id: "5f626ca1fcfe0005857e823f",
    Image: "image url",
    Translations: [
       {
          Name": "Push Ups"
       }
    ]
},
{
    _id: "5f626ca1fcfe0005857e82c9",
    Image: "image url",
    Translations: [
       {
          Name": "Weighted Push Ups"
       }
    ]
}]
所以我只想返回正确的转换,以及其中的一些字段,然后还限制特定嵌套对象之外的其他数据

const exercises = await Exercise.find({ '$text': { '$search': 'push' } }, { Image: 1, Translations: 1 }).sort({ _id: 1 });
但这仍然会返回所有翻译,以及每个翻译中的额外数据。有人有什么想法/建议吗