Page 1 of 1

Combining AddUnique and where operators for arrays

Posted: Wed Nov 15, 2023 10:23 am
by Bob.Tern

I would like to add an object to an array if an object with the same does not already exist in the array. For e.g., my object is {
"id": userID,
"userName": userResult.toPublicProfile.Name,
"image": userResult.toPublicProfile.Image,
"badge": ""
}

I can construct the individual queries like below, but is it possible to join the two queries below in a single query. I was unable to find anything in the documentation regarding that.

"body": {
"where": {
"attendeeList": {
"$elemMatch": {
"id": userID
}
}
}
}

"body": {
"attendeeList": {
"__op": "AddUnique",
"objects": [{
"id": userID,
"userName": userResult.toPublicProfile.Name,
"image": userResult.toPublicProfile.Image,
"badge": ""
}]
}
}


Re: Combining AddUnique and where operators for arrays

Posted: Wed Nov 15, 2023 10:26 am
by aantsypau

Appery does not support the merging of these two queries, and for such a scenario, here are two potential solutions:

  1. Initiate two distinct Rest API calls, as demonstrated in your given example.
  2. If you have the value of the object containing the array, local verification can be executed.