Bob.Tern
Posts: 12
Joined: Wed Nov 15, 2023 7:02 am

Combining AddUnique and where operators for arrays

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": ""
}]
}
}

aantsypau
Posts: 26
Joined: Wed May 24, 2023 7:57 am

Re: Combining AddUnique and where operators for arrays

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.

Return to “Issues”