Skip to content Skip to sidebar Skip to footer

.exec Callback Using Returns Is Returning Undefined, But Console.log Do Have Item In It

I have a mongoose query that will populate from other collection, then will match the populated's query, and then execute a callback function that will filter out null elements. Th

Solution 1:

you can use async/await

const orders = async ()=>{
  let docs = await Order.find().populate('buyer_id', null, { name: { $regex: localQuery } })
  docs = docs.filter(function (doc) { return doc.buyer_id != null; });
  return docs 
  }

Post a Comment for ".exec Callback Using Returns Is Returning Undefined, But Console.log Do Have Item In It"