I have an array of IDs looks like
get profiles [ '62d80ece61a85d738fa0c297', '62d80fb061a85d738fa0c29c' ]
I want to loop this array and every index use it in find() method
My code looks like
let total = [];
profile.forEach(async (index) => {
console.log('index', index);
//OUtput of the console of index
//index 62d80ece61a85d738fa0c297
//index 62d80fb061a85d738fa0c29c
let user = await this.userModel.findOne({ _id: index });
total.push(user);
console.log('Service', total);
//Output of service is Service []
Thanks in advance
Without any information about the schema one solution that I can propose is explicit convert the string to ObjectId