Answers for "async loop with mongoose"

0

async loop with mongoose

// Sort by symbol, skip the first 5, return at most 20, and don't hydrate
// the returned doc. See https://mongoosejs.com/docs/api.html#model_Model.hydrate
const query = Stock.find().sort({ symbol: 1 }).skip(5).limit(20).lean();
for await (const stock of query) {
  const price = await superagent.
    get(`https://api.iextrading.com/1.0/stock/${stock.symbol}/price`).
    then(res => res.body);
  console.log(stock.symbol, price);
  // No `save()` because `stock` is lean
}
Posted by: Guest on October-05-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language