Add Data to Array
POST
/api/collections/data/array/update/addUpdate Elements in an Array
Update Elements in an Array by adding new element or removing an existing element in the array.
If your document contains an array field, you can use arrayUnion()
and arrayRemove()
to add and remove elements. arrayUnion()
adds elements to an array but only elements not already present. arrayRemove()
removes all instances of each given element.
:::warning
The Array Update operation is only available for Array fields and will only work if the Field has either been declared during a Add
operation or has been updated with a Update
operation. If the Field doesn't exist, the Array Update operation will fail.
:::
Add Elements to an Array
To add elements to an array field, use the arrayUnion()
method:
curl --request POST \
--url https://api.worqhat.com/api/collections/data/array/update/add \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"collection": "Sample Collection",
"docId": "sampleDocId",
"field": "sampleField",
"arrayUnion": "sampleData"
}'
Remove Elements from an Array
To remove elements from an array field, use the arrayRemove()
method:
curl --request POST \
--url https://api.worqhat.com/api/collections/data/array/update/remove \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"collection": "Sample Collection",
"docId": "sampleDocId",
"field": "sampleField",
"arrayRemove": "sampleData"
}'
Request
{
"collection": "testdata2",
"docId": "78220c06-d20b-4c87-9004-86051bbbc712",
"field": "testArray2",
"arrayUnion": "test 1"
}
Request samples
Responses
{
"message": "Array data added successfully",
"processingTime": 334.394875,
"processingId": "cb44a695-b24f-4863-b01e-26735b39397c"
}