0

var arr=[18,5,6,....]; Beneficiary.find({Ward: { $in: arr } }).done(function(err,ben) { if(err) console.log(err); else { console.log(ben); } });

I want to fetch those records from Beneficiary collection where Ward are from arr list. This code gives no error but returns blank array []. Although data is there in the database.

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
user3736968
  • 85
  • 2
  • 5

2 Answers2

0

Use $in keyword only if you are playing with Collection.native(...). Since you are not, use:

Beneficiary.find({ Ward: arr }); As you can see in docs.

Theadd
  • 38
  • 5
0

You can not directly use array in IN operator you can use like this :

Beneficiary.find({Ward: { $in: [arr[0],arr[1]] } })
Farhana Naaz Ansari
  • 7,524
  • 26
  • 65
  • 105
Debashish Dwivedi
  • 327
  • 2
  • 5
  • 13