Forum Discussion

enmiwong's avatar
enmiwong
Cloud Apps
03-18-2024
Solved

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

Hi, I'm having data with the following format: { "dataset_id": "4ac54805-18a2-46a6-afb7-8829eb0e1a27",         "configurationDetails": {             "measurementType": "Generic Dataset",       ...
  • AntonV's avatar
    03-22-2024

    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"