0

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

V.V
  • 3,082
  • 7
  • 49
  • 83

1 Answers1

1

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

db.getCollection('test').find({
  $and: [
    {
      "title": 'title' --> Here
    },
    {
      "address.countryName": 'country' --> Here
    }
  ]
})
Gibbs
  • 21,904
  • 13
  • 74
  • 138
  • let me try with this – V.V Jul 14 '20 at 13:44
  • Let me know your sample data also if you face any problem. – Gibbs Jul 14 '20 at 13:49
  • hi tried with this ( { $and: [ { "title":title1 }, { "address.countryName":country } ] } ) my data set is : address: address1:null address2:null city:"Miami" state:"Arizona" zip:null countryID:1 countryName:"United States" countryCode:"US", "title":"United States" but system is reuning 0 objects – V.V Jul 14 '20 at 14:45
  • Because you have no data with `title`. Please use `United States` in place of `title` value. And use proper country name from your document also – Gibbs Jul 14 '20 at 15:14