CouchDB / PouchDB mango query: has in array

Viewed 1242

Is it possible with mango query to find those documents, which have a provided string in an array field?

Say,

const doc = {
  _id: 'testdoc',
  tags: ['pouch', 'couch', 'mysql'],
}

$db.find({ selector: {
  tags: {
    $has: 'pouch' // what goes here?
  } 
}})
1 Answers

You have to use the $elemMatch operator

{
  selector: {
    tags: {
      "$elemMatch": { $eq: "pouch" }
    }
  }
}

For further documentation, head here

Related