Hi,
I am using Couchbase v6.0. I am looking for best optimum solution/approach from performance perspective for updating multiple attributes within array and nested array via N1QL. Though, I have come up with an approach but I see there are multiple loops required with this approach( no of attributes to update== no of loops to be performed in array and the level of loop increments as you go in nested arrays).
Below is the document structure for example:
{
"docType": "std",
"version": 1,
"class": "10th",
"course": "IT",
"school": "HCHSS",
"student": [
{
"email": "abc@gm.com",
"name": "Rahul",
"phoneNr": "123456",
"surname": "Sharma",
"subject": [
{
"maths": 75,
"english": 85,
"examType": "Quaterly"
},
{
"maths": 95,
"english": 65,
"examType": "halfyearly"
}
]
},
{
"email": "def@gm.com",
"name": "Rohit",
"phoneNr": "657453",
"surname": "Verma",
"subject": [
{
"maths": 55,
"english": 75,
"examType": "Quaterly"
},
{
"maths": 90,
"english": 70,
"examType": "halfyearly"
}
]
}
]
}
Below is the N1QL Query:
UPDATE Student_Db
SET class =â11thâ,
course=âITTâ,
std.email=âupabc@123.comâ for std in student WHEN std.name = âRahulâ and std.surname = âSharmaâ END,
std.phoneNr=â7657822â for std in student WHEN std.name = âRahulâ and std.surname = âSharmaâ END,
sub.maths = 50 for sub IN std.subject for std in student WHEN std.name = âRahulâ and std.surname = âSharmaâ and sub.examType=âQuaterlyâ END
Where meta().id = âstudentâ
-
Is thee any better solution/approach available to perform multiple attributes update inside array and nested array using N1QL.
-
I am using .NET Couchbase SDK and Sub-document API in application. To achieve the same via SDK, I can use Upsert/Replace method but that will replace the entire document which might be like passing huge amount of data over network everytime even if just 6-7 attributes are to be updated in whole document. So not sure, how much document size is ideal to pass over network (my document can grow in MB, probably upto 3-4 MB).
-
If I opt for Sub-Document API, i.e. mutate in methods which only mutates part of the document we want to. But here the problem I see is, to update array elements, we need to pass path by position( something like students[0] , student[0].subjects[0] ). Here we have to rely on indexing and I am not finding way to use expressions(find by attribute like = Student==âRahulâ).
Please suggest which approach should be ideal.