//index.js
let countryName = { "name"=["Bangladesh","India","Australia"] }
//Output Section let getCountryData = awaitDataModel.find({$indexOfArray:{CountryName:"Bangladesh"}}) console.log(getCountryData); //Expecting Output: 0
$indexOfArray
is an aggregate operator . Here's a link that shows how to do aggregate in mongoose.
if the array is ["Bangladesh", "India", "Australia"]
I would try something like this
awaitDataModel.aggregate([
{ $indexOfArray: array, "Bangladesh" }
]);
The point is it's an aggregate method and you're using .find
. The above was just pseudo code
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.