Azure Cosmos DB似乎不支持对数组属性的查询(不是关于MongoDB语法的问题)。
预期,在v3.4.9本地工作:
> db.test.insertOne({'Name': 'Bob', Children: ['Rex']})
> db.test.find({Children: {$exists: true, $not: {$size: 0}}})
{ "_id" : ObjectId("59baff11002b35f7ea2864a4"), "Name" : "Bob", "Children" : [ "Rex" ] }
> db.test.find({$where: 'this.Children.length>0'})
{ "_id" : ObjectId("59baff11002b35f7ea2864a4"), "Name" : "Bob", "Children" : [ "Rex" ] }
在Azure Cosmos DB上:
> db.test.insertOne({'Name': 'Bob', Children: ['Rex']})
> db.test.find({Children: {$exists: true, $not: {$size: 0}}})
Error: error: {
"_t" : "OKMongoResponse",
"ok" : 0,
"code" : 2,
"errmsg" : "Request is malformated",
"$err" : "Request is malformated"
> db.test.find({$where: 'this.Children.length>0'})
Error: error: {
"_t" : "OKMongoResponse",
"ok" : 0,
"code" : 2,
"errmsg" : "Request is malformated",
"$err" : "Request is malformated"
}
如何找到子项存在但不为空的项目?
更新
本地主机:
> db.test.find({ "Children.0": { "$exists": true }})
{ "_id" : ObjectId("59baff11002b35f7ea2864a4"), "Name" : "Bob", "Children" : [ "Rex" ] }
Cosmos DB:
> db.test.find({ "Children.0": { "$exists": true }})
>