E
E
ExcaliBUR952022-02-28 23:55:39
JavaScript
ExcaliBUR95, 2022-02-28 23:55:39

How to calculate sum of array elements in mongoose?

In general, you need to create a pharmacy, and there are 4 models, medicines, customers, pharmacy and medicine categories.
In the cart, you need to count the sum of all the goods that are in the cart

const basketSchema = mongoose.Schema({
    user: {
        ref: "Client",
        type: mongoose.Schema.Types.ObjectId
    },
    product: {
       
        ref: "Drug",
        type: mongoose.Schema.Types.ObjectId,
        total: temp + Drug.product 
    }
})


+ more additional questions
Can someone explain what the aggregation and the lookup method do
users
  .aggregate([
    {
      $lookup: {
        from: 'rooms',
        localField: 'room_id',
        foreignField: 'id',
        as: 'room_details',
      },
    },
  ])

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question