CosmosDB mongodb - $all 结合 $elemMatch 查询嵌套对象集合未按预期工作
CosmosDB mongodb - $all combined with $elemMatch query on nested collection of objects not working as expected
我正在使用 CosmosDB(mongodb-api)。
对于此示例,我使用以下文档:
/* 1 */
{
"_id" : "abspi4lxwfbfjahdvjm3clnnl4",
"categories" : [
{
"_name" : "category-1",
"date" : NumberLong(1540373282070),
"string" : "20",
"number" : 20
},
{
"_name" : "category-2",
"string" : "1",
"number" : 1
}
]
}
/* 2 */
{
"_id" : "ggi36vpvprdbrdnji5otypbh3e",
"categories" : [
{
"_name" : "category-2",
"date" : NumberLong(1540373282071),
"string" : "1",
"number" : 1
}
}
}
/* 3 */
{
"_id" : "kdh3jdyenapq54clufgajmgfy8",
"categories" : [
{
"_name" : "category-1",
"date" : NumberLong(1540373282070),
"string" : "20",
"number" : 20
},
{
"_name" : "category-2",
"string" : "1",
"number" : 1
},
{
"_name" : "category-3",
"string" : "29",
"number" : 29
}
]
}
我需要检索文档 1 和 3,下一个查询匹配在 mongoDB 中完美运行。
db.getCollection('test_collection')
.find({"categories":{
"$all":[
{"$elemMatch":{"number":20}},
{"$elemMatch":{"number":1}}
]
}
})
在 CosmosDB 中 return 0 records.It 似乎不支持 cosmosDB 中超过 1 个 elemMatch。
知道是否可以使用 mongoDB-api 在 CosmosDB 中进行查询吗?
In CosmosDB return 0 records.It seems that more than 1 elemMatch in
cosmosDB is not supported.
是的,根据我的测试,Cosmos Mongo API 不支持 $and
运算符和超过 1 个 elemMatch 条件的组合。据我所知,CosmosDB 仅支持 MongoDB API 的一个子集,并将请求转换为 CosmosDB SQL 等效项。 CosmosDB 有一些不同的行为和结果。但是 CosmosDB 有责任改进他们对 MongoDB 的模拟。
当然,如果您想要完整的 MongoDB 功能支持,您可以在 Azure 上添加反馈 here to submit your requirements or consider using MongoDB Atlas。
2018 年 10 月末创建的新数据库已解决此问题。
我们做了很多测试来测试兼容性并且工作正常。
这次我们很幸运,一直在考虑将所有系统更改为具有 SQL 查询的 documentDB。
我希望post能帮助其他可能遇到同样情况的人。
我正在使用 CosmosDB(mongodb-api)。
对于此示例,我使用以下文档:
/* 1 */
{
"_id" : "abspi4lxwfbfjahdvjm3clnnl4",
"categories" : [
{
"_name" : "category-1",
"date" : NumberLong(1540373282070),
"string" : "20",
"number" : 20
},
{
"_name" : "category-2",
"string" : "1",
"number" : 1
}
]
}
/* 2 */
{
"_id" : "ggi36vpvprdbrdnji5otypbh3e",
"categories" : [
{
"_name" : "category-2",
"date" : NumberLong(1540373282071),
"string" : "1",
"number" : 1
}
}
}
/* 3 */
{
"_id" : "kdh3jdyenapq54clufgajmgfy8",
"categories" : [
{
"_name" : "category-1",
"date" : NumberLong(1540373282070),
"string" : "20",
"number" : 20
},
{
"_name" : "category-2",
"string" : "1",
"number" : 1
},
{
"_name" : "category-3",
"string" : "29",
"number" : 29
}
]
}
我需要检索文档 1 和 3,下一个查询匹配在 mongoDB 中完美运行。
db.getCollection('test_collection')
.find({"categories":{
"$all":[
{"$elemMatch":{"number":20}},
{"$elemMatch":{"number":1}}
]
}
})
在 CosmosDB 中 return 0 records.It 似乎不支持 cosmosDB 中超过 1 个 elemMatch。 知道是否可以使用 mongoDB-api 在 CosmosDB 中进行查询吗?
In CosmosDB return 0 records.It seems that more than 1 elemMatch in cosmosDB is not supported.
是的,根据我的测试,Cosmos Mongo API 不支持 $and
运算符和超过 1 个 elemMatch 条件的组合。据我所知,CosmosDB 仅支持 MongoDB API 的一个子集,并将请求转换为 CosmosDB SQL 等效项。 CosmosDB 有一些不同的行为和结果。但是 CosmosDB 有责任改进他们对 MongoDB 的模拟。
当然,如果您想要完整的 MongoDB 功能支持,您可以在 Azure 上添加反馈 here to submit your requirements or consider using MongoDB Atlas。
2018 年 10 月末创建的新数据库已解决此问题。 我们做了很多测试来测试兼容性并且工作正常。
这次我们很幸运,一直在考虑将所有系统更改为具有 SQL 查询的 documentDB。
我希望post能帮助其他可能遇到同样情况的人。