0

Azure Cosmos DB doesn't seem to support queries on array properties (not question about MongoDB syntax).

Expected, Working locally on 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" ] }

On 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"
}

How can I find items where Children exists but is not empty?

UPDATE:

Localhost:

> db.test.find({ "Children.0": { "$exists": true }})
{ "_id" : ObjectId("59baff11002b35f7ea2864a4"), "Name" : "Bob", "Children" : [ "Rex" ] }

Cosmos DB:

> db.test.find({ "Children.0": { "$exists": true }})
>
Jonas Stensved
  • 14,378
  • 5
  • 51
  • 80
  • `db.test.find({ "Children.0": { "$exists": true }})`. It's always been a more reliable test of an existing array anyway. Basically if the `0` index ( first element ) is present, then there must be something in the array. – Neil Lunn Sep 14 '17 at 22:38
  • Yes. Tried it. This query also fails on Cosmos DB? – Jonas Stensved Sep 14 '17 at 22:42
  • 1
    I would then suggest either using the native CosmosDB API instead or not using CosmosDB at all. There really does seem to be a large number of incompatibilities for something claiming to be a "drop in replacement". So the issue is with "support of features" and nothing to do with the query being issued. – Neil Lunn Sep 14 '17 at 22:44
  • Yes. My question is specific to Cosmos DB. – Jonas Stensved Sep 14 '17 at 22:46

0 Answers0