2

I have an Microsoft Azure CosmosDB MongoDB Api database and I am trying to get all the documents where one array field is fully contained in my search array.

So, what I am looking for is, given the collection test containing the documents: {"id":1,"filters":[1,2]} {"id":2,"filters":[1,3]}

if I execute: db.test.find({"filters":{"$elemMatch":{$nin: [1,3]}}})

I get back: {"id":1,"filters":[1,2]}

However, if I negate it, since I want all the documents with filters fully contained in my search, the full list of documents is returned. db.test.find({"filters":{$not:{"$elemMatch":{$nin: [1,3]}}}})

returns:

{"id":1,"filters":[1,2]} {"id":2,"filters":[1,3]}

contrary to what is mentioned in the article: Check if every element in array matches condition

I also tried the $issubset on an aggregation , to no avail ( 0 results ) :

db.test.aggregate([{$match:{$issubset:["$filters",[1,3]]}}])

I even tried ( 0 results ):

db.test.aggregate([{$match:{$issubset:[[1],[1,3]]}}])

Anyone with an idea of what is happening her?

  • Is it my error?

  • List item Am I using mongoDB features not implemented in CosmosDB yet?

  • Is it CosmosDB bug?

Thank you!

  • Detailing a little further: I need the documents with all the elements in the filter array contained in my search to be returned. So even if the document has only a partial match but no matches outside of the search it should still be returned. adding this to the initial question... – Tiago Nunes Sep 08 '17 at 07:41

1 Answers1

0

I encountered a server error when testing $nin on my side. Then I tried to use $and to combine multi sub queries and it worked fine. Please using following code to query all the documents with filters fully contained in your search.

{ "filters": NumberInt(1), $and: [ { "filters": NumberInt(3) } ] }
Amor
  • 8,325
  • 2
  • 19
  • 21
  • Hi, thanks, sorry for the late reply, it does not fulfill exactly what I was trying to explain: I need the documents with all the elements in the filter array contained in my search to be returned. So even if the document has only a partial match but no matches outside of the search it should still be returned. adding this to the initial question... – Tiago Nunes Sep 08 '17 at 07:40