我将 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';
它应该只返回第一个文档,但它返回了两个,因为第二个文档有一个标签,key = number 和 value = 1(这是因为值)。
是否有可能只获得第一个文件?查询应该是什么样子?
Drill 将集合转换为这样的表:
+---------------------------------------------------------------+
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
并且没有关系运算符可以为您执行此匹配。
关于sql - 带有 mongodb 的 Apache Drill。在 map 中查询具有特定键和值的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47456764/