0

I have the following json document on my couch db.

{ 
  {
      "_id": "someid|goes|here",
      "collected": {
          "tags": ["abc", "def", "ghi"]
      }
  },
  {
      "_id": "someid1|goes|here",
      "collected": {
           "tags": ["abc", "klm","pqr"]
      },
  },
  {
      "_id": "someid2|goes|here",
      "collected": {
           "tags": ["efg", "hij","klm"]
      },
  }
}

How can I get the records where collected.tags contains abc? What I have tried so far is

{
   "selector": {
      "collected.tags": {
         "$regex": "abc"
      }
   }
}
Abishek
  • 11,191
  • 19
  • 72
  • 111

1 Answers1

0

If I've understood correctly you are querying this from 3 different documents. Using the $elemMatch operator as per CouchDb Documentation it's possible to return all documents where at least one element that is matched based on the specified criteria. If so use the following query to filter out the text "abc":

{
  "selector": {
    "collected.tags": {
      "$elemMatch": {
        "$regex": "abc"
      }
    }
  }
}

Hope this helps out. :)

imaadhrizni
  • 428
  • 4
  • 11
  • since the question is a duplicate of a previous one, I have marked it as duplicate. Thanks for the effort anyways. Appreciate it. – Abishek May 30 '19 at 16:48