I am currently working with Mongoose and Typescript, and my document structure is as follows:
{
_id: 1,
id: "a",
markets: [{
type: "car",
price: 10000},
{type: "toy",
price: 10},...]
}
{
_id: 2,
id: "b",
markets: [{
type: "car1",
price: 1023400},
{type: "toy1",
price: 1032},...]
}
{
_id: 3,
id: "c",
markets: [{
type: "car2",
price: 10000},
{type: "toy2",
price: 1023},...]
}
I have a specific requirement to update the following part in the document based on id and type (specifically, when id="a" and markets.type="car" before updating), ensuring uniqueness: for example: replacing
{type: "car", price: 10000}
with {type: "car3", price: 11200}
, how can I achieve this using Mongoose?