Subdoc mutatein to remove element from array

Hi,

How can I remove an element using mutatein .
Document is something like this
{
“id”:“456”,
“name”:“srikar”,
“flightname”:“xyz”,
“booking”:[{“bookingid”:""1234,“date”:“2017-05-04”},{“bookingid”:“456789”,“date”:“2017-05-03”} ],
“address”:“wehedwhwe”
}

How can I remove a booking item where bookingid is “456789” using mutatein.

If not can any one suggest me alternative to achieve result.

Regards.
Srikar

1 Like

try this

SELECT default.name, default.flightname, default.address ,ARRAY_AGG(book) AS booking
  FROM default USE KEYS ["456"] UNNEST booking book 
 WHERE book.bookingid != "456789"
 GROUP BY default.name, default.flightname, default.address

what does ‘default’ stands for , is this bucket name?

yes ,you can change it to your bucket name.

Thanks,
I tried it is working, but I need to update(removing particular booking item) database, which was not happening with select.

Can you please help me with update query. no need of returning results back.

FYI

UPDATE default USE KEYS ["456"]
   SET booking = ARRAY book 
   FOR book IN booking WHEN book.bookingid != "456789" END 
RETURNING *;

more detail, FYI

2 Likes