简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM