1

I have stored the following document in my Cosmos DB using the Mongo API:

{
    "_id" : ObjectId("59157eaabfeb1900011592c8"),
    "imageResourceId" : "1489496086018.png",
    "gallery" : "Tst",
    "thumbnailRaw" : {
        "$binary" : "<SNIP>",
        "$type" : "00"
    },
    "tags" : [
        "Weapon/Sword",
        "Japanese"
    ],
    "__v" : 1
}

I'm trying to perform a query that excludes any objects containing the tag "Japanese". I've crafted the following query, which performs correctly (that is, it does not return the above document) on a real Mongo DB:

{"gallery":"Tst, "tags":{"$nin":["Japanese"]}}

On Cosmos DB, this query returns the above image, despite the presence of a string found in the $nin array. Am I doing this query correctly? Is there another, supported way for Cosmos DB to do a NOT IN logical operation?

Jared Harding
  • 4,942
  • 2
  • 17
  • 14
  • 1
    It seems that the API is incomplete. I experience some queries that are working on MongoDb but fail on CosmosDb – Alexey Zimarev Jun 02 '17 at 08:35
  • 2
    It's really bad that Microsoft doesn't specify which version or level of MongoDB API cosmosDB supported. It turns out that cosmosDB's support to current MongoDB API v3.4 is very limited, and missing a lot of functions. And worse, there are very scarce documentation either – Marshal Jun 15 '17 at 01:43

1 Answers1

0

I have a different issue with CosmosDB, that made me run a few tests on operations with arrays, I believe that in your case this should work:

db.gallery.find({"tags":{"$elemMatch":{$nin: ["japanase"]}}} )

my issue:

Azure Cosmos DB check if array in field is contained in search array

I agree with the comment that CosmosDB is implementing only a subset of mongoDB, and documentation is very scarce, but I hope the fix I propose works for you.