在数组中的嵌套文档中搜索子字符串

时间:2017-07-05 21:25:59

标签: mongodb mongodb-query

情况

有一个类似的文件:

{
  ttl: [
    {
      lng: 'en',
      txt: 'English text example'
    },
    {
      lng: 'es',
      txt: 'Spanish text example'
    }
  ]
}

我需要在此集合的所有文档中的字段 txt 中编写查询子字符串的查询。

问题

我写了一个查询:

db.collection.find({
  ttl: {
    $elemMatch: {
      txt: {
        $text: {
          $search: data
        }
      }
    }
  }
});

但我发现,我无法在数组中使用方法 $ text

问题

如何搜索数组中嵌套文档中的子字符串?还有其他方法吗?

PS

$ elemMatch:Link to the article
$ text:Link to the article

0 个答案:

没有答案
相关问题