mongodbmongodb-querymongodb-stitch

not able to fetch using $and in mongo db


I'm trying to use $and in mongodb stitch function to get data using 2 different condition

data = col.find( { $and: [ { "title": { title } }, { "address.countryName": { country } } ] } ).toArray;

but this shows $undefined:true in response.

please guide what is wrong in here


Solution

  • You need to remove {} in the condition's value

    db.getCollection('test').find({
      $and: [
        {
          "title": 'title' --> Here
        },
        {
          "address.countryName": 'country' --> Here
        }
      ]
    })