I am currently trying to append a new json object to an array, and then sort the array correctly. This is my current query for appending the object to the bottom of the array, which works fine. What would need to be added in order to order the objects by a certain field AFTER appending the new object?
@Query("MERGE INTO #{#n1ql.bucket} AS d USING [1] AS o ON KEY $1 " +
"WHEN MATCHED THEN UPDATE SET d.schedule = ARRAY_SORT(ARRAY_APPEND(d.schedule, $2)) " +
"WHEN NOT MATCHED THEN INSERT $3")
@Query("MERGE INTO #{#n1ql.bucket} AS d USING [1] AS o ON KEY $1 " +
"WHEN MATCHED THEN UPDATE SET d.schedule = (SELECT * FROM ARRAY_APPEND(d.schedule, $2) as b ORDER BY b.start_time) " +
"WHEN NOT MATCHED THEN INSERT $3")
Came up with this solution, although it is close, each array object is given the title ‘b’, when I don’t want them to be named at all. Any ideas would be appreciated
@Query("MERGE INTO #{#n1ql.bucket} AS d USING [1] AS o ON KEY $1 " +
"WHEN MATCHED THEN UPDATE SET d.schedule = (SELECT RAW b FROM ARRAY_APPEND(d.schedule, $2) as b ORDER BY b.start_time) " +
"WHEN NOT MATCHED THEN INSERT $3")