简体   繁体   中英

how to get array index from mongoose Array

//index.js

 let countryName = { "name"=["Bangladesh","India","Australia"] }

 //Output Section let getCountryData = awaitDataModel.find({$indexOfArray:{CountryName:"Bangladesh"}}) console.log(getCountryData); //Expecting Output: 0
I want the index of array from mongoose data set

$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.

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