Hi,
I have a my schema as below.
{
name : "A",
outerArr : [
{
outerId : 1,
innerArr : [
{
{ date: '2023-08-1', type: 'Normal'},
{ date: '2023-08-2', type: 'Normal'},
{ date: '2023-08-3', type: 'Normal'}
}
]
},
{
outerId : 2,
innerArr : [
{
{ date: '2023-08-1', type: 'Normal'},
{ date: '2023-08-2', type: 'Normal'},
{ date: '2023-08-3', type: 'Normal'}
}
]
},
{
outerId : 3,
innerArr : [
{
{ date: '2023-08-1', type: 'Normal'},
{ date: '2023-08-2', type: 'Normal'},
{ date: '2023-08-3', type: 'Normal'}
}
]
}
]
}
I have a mongodb updateOne command which is working great in mongo shell. I want to do it via spring mongo data. Could you please help me writing the updateOne syntax in spring mongodb ?
Here is the mongodb updateOne method query and update syntax
const innerArr = {
"$elemMatch": {
"date": "2023-08-3",
"type": "Normal"
}
};
db.xyz.updateOne(
{
"name": "A",
"outerArr": {
"$all": [
{
"$elemMatch": {
"outerId": 1,
"innerArr": innerArr
}
},
{
"$elemMatch": {
"outerId": 2,
"innerArr": innerArr
}
},
{
"$elemMatch": {
"outerId": 3,
"innerArr": innerArr
}
}
]
}
},
{
"$set": {
"outerArr.$[i].innerArr.$[j].type": "Reserved"
}
},
{
"arrayFilters": [
{ "i.outerId": { "$in": [1, 2, 3] } },
{ "j.date": "2023-08-3" }
]
}
)