Document Structure
{
"_id": {
"$oid": "61e6e300f78f707b9c3ec32f"
},
"userId": "61d51daa0e09c2a97f11c81d",
"services": [
{
"sId": "62036c3cde7ac3b60203bdb5",
"status": 1,
"permissionGroups": [
{
"pgId": "61e52858b6d31433bb7faf6c",
"status": 1,
"permissions": [
{
"pId": "61e3f5891e0b130b3a228ff0",
"status": 1
},
{
"pId": "61e4ec54974ad2600b58f2ad",
"status": 1
},
{
"pId": "61e4ec54974ad2600b58f2ae",
"status": 1
}
]
},
{
"pgId": "61e8456e5b1359cb2b89888c",
"status": 1,
"permissions": [
{
"pId": "61e5086fd3af37389f1ba2a0",
"status": 1
},
{
"pId": "61e50870d3af37389f1ba2a1",
"status": 1
},
{
"pId": "61e52313f1a85a169f4f9afd",
"status": 1
},
{
"pId": "61e525c4f1a85a169f4f9b00",
"status": 1
}
]
}
]
}
]
}
Im trying to update a field in the nested document (above mentioned) using mongo query in springboot. my purpose is to update the field called status inside permissions array. i know the query to update it using mongo shell, can someone help me convert the query to java or suggest me a way to do the same.
db.customer_service_details.update(
{
"userId": "61d51daa0e09c2a97f11c81d",
"services": {
"$elemMatch": {
"sId": "62036c3cde7ac3b60203bdb5","permissionGroups.pgId": "61e52858b6d31433bb7faf6c","permissionGroups.permissions.pId":"61e3f5891e0b130b3a228ff0"
}
}
},
{
"$set": { "services.$[outer].permissionGroups.$[inner].permissions.$[inner3].status": "7899" }
},
{
"arrayFilters": [{ "outer.sId": "62036c3cde7ac3b60203bdb5" },{ "inner.pgId": "61e52858b6d31433bb7faf6c" },{"inner3.pId":"61e3f5891e0b130b3a228ff0"}]
}
)