javascriptnode.jscouchdbcouchdb-futoncouchdb-mango

How to connect operator $or & $and in couchDb mango?


I have document in witch has field "leader". Leader can be type string or array. For example {leader: "id"} or {leader: ["id"]}. How I can get all document where leader = id; If I use operator $all, I search in array, if use operator $or I search in field(string). How I can to connect them ? I don't want to do two request. Field has differents type because was had changed structure. Thanks.

"selector": {
      "leaderId": {
         "$all": ["id"]
      }
   }

Solution

  • Try this

    db.collection.find({$or : [{"leader" : "id"}, {"leader" : { $all : ["id"] }}]})