mongodb-querycouchdbcloudantcouchdb-mango

Creating a Mango query selector for element that do NOT match


I have a user like so:

{
  "_id": "u88888",
  "_rev": "27-9f205fb7496645be2f3d717fff376d73",
  "name": "Test Testerson",
  "type": "user",
  "role": "boss",
  "training": [
    {
      "id": "11111",
       "name": "training 1"
    },
    {
      "id": "33333",
      "name": "training 3"
    }
  ]
}

I'm trying to run a query to find the following:

I do the following selector, however, this user comes up and I'm not sure why:

selector:{
    "$and": [
        { "type": "user" },
        { "role": "boss" },
        { "training": { "$ne": { "id": "11111" } } }
    ]
}

Solution

  • Found an answer. This ended up working:

    { training: { $not: {$elemMatch: {id: "11111" } } }