I am having trouble updating an array within a MongoDB document using Mongoose. Below is my stock model definition:
const ticker = new mongoose.Schema({
ticker: String,
Price: Number,
Amount: Number,
PastPrices: [Number]
});
export const stock = mongoose.model("Stocks", ticker);
Here is an example document in MongoDB:
{
"_id": {
"$oid": "61e5d0e1dfda4d7c85dc8fe2"
},
"PastPrices": [
2
],
"ticker": "TSLA",
"Price": 2,
"Amount": 0,
"__v": 0
}
Despite running the update operation with Mongoose, the PastPrices array is not being updated as expected. My goal is to continuously add values to this array every few seconds and eventually display them on a chart.
stock.updateOne({ticker: "TSLA"},
{ $push: { PastPrices:1}}
);
No error messages are being displayed, but the array is simply not updating as intended.