Apache Drill mongodb。在地图中查询具有特定键和值的文档

Apache Drill with mongodb. Query for documents with particular keys and values within a map

我将 apache drill 与 mongodb 一起使用。我在 mongodb 中的文档如下所示:

{
  "labels": [{
              "key": "product",
              "value": "shampoo"
              },
              {
               "key": "id",
               "value": "1"
               },
              {
               "key": "number",
               "value": "0"
               }]
 },
 "labels": [{
              "key": "product",
              "value": "shampoo"
              },
              {
               "key": "id",
               "value": "2"
               },
              {
               "key": "number",
               "value": "1"
               }]
 }

我想查询有e的文档。 G。标签 {"key": "id", "value": "1"}

我用这个查询试过了:

select * from myCollection where `labels.key` = 'id' and `labels.value` = '1';

它应该 return 只有第一个文件,但它 return 两者都是,因为第二个文件有一个标签,键 = 数字,值 = 1(这是因为值).

有没有可能只获得第一个文件?查询应该是什么样子?

Drill 将集合转换为 table:

+---------------------------------------------------------------+
                                labels
+---------------------------------------------------------------+
[{"key": "product", "value": "shampoo"}, {"key": "id", "value": "1"},...]
[{"key": "product", "value": "shampoo"}, {"key": "id", "value": "2"}, ...]
+----------------------------------------------------------------+

这在 Apache Drill 中是不可能的。

在 MongoDB 中,您可以使用 $elemMatch 运算符表达此条件,例如:

db.collection.find(
   { labels: { $elemMatch: { key: "id", value: "1" } } }
)

但是,Apache Drill 的 Mongo 存储插件不支持 $elemMatch 运算符。

original documentation for Apache Drill's Mongo storage plugin 表示:

As of now, predicate pushdown is implemented for the following filters: >, >=, <, <=, ==, !=, isNull and isNotNull.

查看 latest version of the code 情况仍然如此...不支持 $elemMatch 并且没有关系运算符可以为您执行此匹配。