MutateIn.Remove to delete perticular element inside a array

i have a csn array in my document as shown below. i want to delete a perticular element using MutateIn.Remove() method:

“opldCns”: [
{
“bpyAtnNa”: “”,
“bpyCoNa”: “JOHN MAPLES”,
“lstSmtDt”: “08-23-18 07:56:34”,
“pkgQy”: 1
},
{
“bpyAtnNa”: “”,
“bpyCoNa”: “JOHN MAPLES”,
“lstSmtDt”: “08-22-18 07:56:34”,
“pkgQy”: 1
},
{
“bpyAtnNa”: “”,
“bpyCoNa”: “JOHN MAPLES”,
“lstSmtDt”: “11-21-17 07:56:34”,
“pkgQy”: 1
},
{
“bpyAtnNa”: “”,
“bpyCoNa”: “JOHN MAPLES”,
“lstSmtDt”: “02-12-19 07:56:34”,
“pkgQy”: 1
}
]

I have tried as below but it is deleting the entire array i want to delete a specific element how i can achieve that
var status = servicePointBucket.MutateIn(“docid”)
.Remove(“cns”).Execute().Status;

I am able to do this using update N1QL query but i want to do this using MutateIn please help…

When using the sub-document API (via MutateIn) you can only reference specific paths within a documents to mutate - for example if you wanted to remove the first array element you’d use the path:

cns[0]

1 Like

In the .NET SDK, there are also helper extension methods that can use lambda syntax to generate the subdoc path.

var status = servicePointBucket.MutateIn("docId").Remove(p => p.Cns[0]).Execute().Status;
1 Like

var status = servicePointBucket.MutateIn(“docId”).Remove(p => p.Cns.Select(i=>i.id==“123”)).Execute().Status;
Is something like this achievable by sub document SDK as relying on index can lead to incorrect update if index position gets updated by another thread.