Untitled

 avatar
unknown
plain_text
2 years ago
741 B
2
Indexable
const MAX = 300
      const cursor = await this.stockModel
        .find({
          prices: { $ne: null },
        })
        .cursor()
      let document
      while ((document = await cursor.next())) {
        const increase = (document?.prices[0]?.price[0] || 0) * percent
        const price =
          increase > MAX
            ? (document?.prices[0]?.price[0] || 0) + MAX
            : (document?.prices[0]?.price[0] || 0) + increase
        await this.stockModel.updateOne(
          {
            _id: document._id,
          },
          {
            $set: {
              'prices.0.price.0': price,
              salePriceString: price?.toString() || '0',
            },
          },
        )
      }