cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete element in an array by id in nested object using custom data api

enmiwong
8 - Cloud Apps
8 - Cloud Apps

Hi, I'm having data with the following format:

{
"dataset_id": "4ac54805-18a2-46a6-afb7-8829eb0e1a27",
        "configurationDetails": {
            "measurementType": "Generic Dataset",
            "fields": [
                {
                    "id": "0",
                    "name": "Id",
                    "type": "Property",
                    "dataType": "Integer",
                    "count": 150,
                    "visibility": true
                }
              ]
          }
}
 
I want to delete fields with id=0, how to write the query for the delete custom data endpoint here: https://sisense.dev/guides/restApi/custom-data.html#:~:text=DELETE,v1/custom_data/query
1 ACCEPTED SOLUTION

AntonV
Sisense Team Member
Sisense Team Member

I am not asking you why you're doing this, but the technical answer to your question is:

db.collection.updateOne({"dataset_id": "4ac54805-18a2-46a6-afb7-8829eb0e1a27"},{"$pull":{"configurationDetails.fields":{"id": "0"}}})

It will remove the entire element of the 'fields' array with "id": "0"

View solution in original post

2 REPLIES 2

AntonV
Sisense Team Member
Sisense Team Member

I am not asking you why you're doing this, but the technical answer to your question is:

db.collection.updateOne({"dataset_id": "4ac54805-18a2-46a6-afb7-8829eb0e1a27"},{"$pull":{"configurationDetails.fields":{"id": "0"}}})

It will remove the entire element of the 'fields' array with "id": "0"

DRay
Community Team Leader
Community Team Leader

Hello @enmiwong,

I wanted to follow up to see if the solution offered by @AntonV worked for you.

If so, please click the 'Accept as Solution' button so that other users with the same questions can find the answer faster. If not, please let us know so that we can continue to help.

Thank you.

David Raynor (DRay)