Problem
- I made some code to perform arithmetic operations as I am working on billing software.
- This code snippet is causing issues
await shopCollection.updateOne(
{ Barcode: elem.Barcode },
{
$set: {
Quantity: { $subtract: ["$Quantity", #elem.Quantity] },
SalesQuantity: {
$add: [{ $ifNull: ["$SalesQuantity", 0] }, elem.Quantity],
},
Profit: { $subtract: ["$SalesPrice", "$CostPrice"] },
TotalProfit: {
$add: ["$TotalProfit", { $multiply: ["$Profit", elem.Quantity] }],
},
SalesTotal: {
$add: [
"$SalesTotal",
{ $multiply: ["$SalesPrice", elem.Quantity] },
],
},
},
},
{ upsert: true, returnOriginal: false }
);
Entire code : https://pastebin.com/b6Zzhv16
It returns a object instead of Int like so
- I am using ubuntu ,running the mongodb community edition and I am not using mongoose or schemas