node pass value to result function

by imin   Last Updated September 11, 2019 17:26 PM

Here's how my code looks like


BadgeTriggered.findOne({ schoolID: mongoose.mongo.ObjectId(schoolID), badgeID: mongoose.mongo.ObjectId(badgeList[i].id)}).then(function (err, data) {
    console.log("get data")
    console.log("and show badgeList below: ")
    console.log(badgeList[i].id)  //badgeList[i] is undefined here

As you can see above, badgeList[i] is actually unavailable when I tried to print out the value inside the bottom console low. So how do I actually pass badgeList to the findOne result function?

Tags : node.js

Related Questions

Updated April 14, 2017 15:26 PM

Updated April 04, 2019 15:26 PM

Updated July 21, 2017 14:26 PM

Updated July 15, 2018 15:26 PM

Updated July 01, 2019 03:26 AM