我们正在使用Mongo Java Client从mongoDB迁移到CosmoDB。我们在使用数组的查询行为中遇到以下差异。
我们的文档类似于以下内容
[{
"name":"garry",
"pets":["cats","dogs"]
},
{
"name":"sally",
"pets":["cats","fish"]
}]
使用mongo查询
find({"pets":"cats"})
将返回garry
和sally
但是使用cosmoDB我们得到零结果。
有没有办法修改查询以复制相同的mongo行为?
我们还有类似以下类型的文档,我们在类型
上查询 [{
"name": "garry",
"pets": [{
"type": "cat",
"name": "Mittens"
}, {
"type": "dog",
"name": "Max"
}]
},
{
"name": "sally",
"pets": [{
"type": "cat",
"name": "Paul"
}, {
"type": "fish",
"name": "Bubbles"
}]
}
]
当前的mongo查询看起来像是
find({"pets.type": "fish"})
在
答案 0 :(得分:0)
我尝试使用下面的查询,它有效。
使用MongoShell。
find({"pets": {$all: ["cats"]}})
对于Mongo Java驱动程序
FindIterable<Document> queryResult = collection.find(Filters.all("pets", "cats"));