How to manipulate firebase snapshot data












1















I am trying to understand how to delete a node inside a snapshot. I have looked at other examples but I did not find something on deleting.



this is what the JSON looks like



    {
"series": {
"audit": null,
"contacts": null,
"images": null,
"products": {
"-LQgKSWzEtN9eVHcVLzV": {
"dataEntryDevice": "FIGGG",
"dataEntryDeviceVersion": "1.0",
"dateTimeUploaded": "2018-11-06T20:02:20-08:00",
"marketId": 19,
"metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
"products": [
{
"auditDate": "11/06/2018",
"bathrooms": "",
"bedrooms": "",
"bestSeller": false,
"garage": "",
"id": "",
"model": false,
"name": "",
"newProduct": false,
"notAvailable": false,
"price": 0,
"stories": "",
"unitsReleased": 0,
"unitsSold": 0
},
{
"auditDate": "11/06/2018",
"bathrooms": "2.5",
"bedrooms": "3",
"bestSeller": false,
"garage": "",
"id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
"model": false,
"name": "Plan 2",
"newProduct": true,
"notAvailable": true,
"price": 0,
"stories": 2,
"unitsReleased": 4,
"unitsSold": 4
},
{
"auditDate": "11/06/2018",
"bathrooms": "3",
"bedrooms": "3",
"bestSeller": false,
"garage": "",
"id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
"model": false,
"name": "Plan 5",
"newProduct": true,
"notAvailable": true,
"price": 0,
"stories": 2,
"unitsReleased": 3,
"unitsSold": 3
},
{
"auditDate": "11/06/2018",
"bathrooms": "4",
"bedrooms": "5",
"bestSeller": false,
"garage": "",
"id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
"model": false,
"name": "Plan 6",
"newProduct": true,
"notAvailable": true,
"price": 0,
"stories": 2,
"unitsReleased": 2,
"unitsSold": 2
}
],
"seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
"userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26"
},
"Optional("-LQgHPWQ1KKElA8zWIKv")": {
"auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"dataEntryDevice": "iPad",
"dataEntryDeviceVersion": "0.9906",
"dateTimeUploaded": "2018-11-06T19:49:02",
"marketId": "19",
"metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
"products": [
{
"auditDate": "2018-11-06T19:49:02",
"bathrooms": "2.5",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 1796,
"garagesNumber": "2",
"id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
"model": false,
"name": "Plan 2",
"newProduct": true,
"notAvailable": false,
"stories": 2
}
],
"seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
"userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"userName": "Lkolokousis@metrostudy.com"
},
"Optional("-LQgHY12QubrBiwU0Uw7")": {
"auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"dataEntryDevice": "iPad",
"dataEntryDeviceVersion": "0.9906",
"dateTimeUploaded": "2018-11-06T19:49:36",
"marketId": "19",
"metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
"products": [
{
"auditDate": "2018-11-06T19:49:02",
"bathrooms": "2.5",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 1796,
"garagesNumber": "2",
"id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
"model": false,
"name": "Plan 2",
"newProduct": true,
"notAvailable": false,
"stories": 2
},
{
"auditDate": "2018-11-06T19:49:36",
"bathrooms": "3",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 2438,
"garagesNumber": "2",
"id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
"model": false,
"name": "Plan 5",
"newProduct": true,
"notAvailable": false,
"stories": 2
}
],
"seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
"userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"userName": "Lkolokousis@metrostudy.com"
},
"Optional("-LQgHeGVu075fgcbBWP7")": {
"auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"dataEntryDevice": "iPad",
"dataEntryDeviceVersion": "0.9906",
"dateTimeUploaded": "2018-11-06T19:50:06",
"marketId": "19",
"metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
"products": [
{
"auditDate": "2018-11-06T19:49:02",
"bathrooms": "2.5",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 1796,
"garagesNumber": "2",
"id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
"model": false,
"name": "Plan 2",
"newProduct": true,
"notAvailable": false,
"stories": 2
},
{
"auditDate": "2018-11-06T19:49:36",
"bathrooms": "3",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 2438,
"garagesNumber": "2",
"id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
"model": false,
"name": "Plan 5",
"newProduct": true,
"notAvailable": false,
"stories": 2
},
{
"auditDate": "2018-11-06T19:50:06",
"bathrooms": "4",
"bedrooms": "5",
"bestSeller": false,
"finishedSqFt": 2753,
"garagesNumber": "2",
"id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
"model": false,
"name": "Plan 6",
"newProduct": true,
"notAvailable": false,
"stories": 2
}
],
"seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
"userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"userName": "Lkolokousis@metrostudy.com"
},
"Optional("-LQgHf1zpDDXs7m7KVNk")": {
"auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"dataEntryDevice": "iPad",
"dataEntryDeviceVersion": "0.9906",
"dateTimeUploaded": "2018-11-06T19:50:09",
"marketId": "19",
"metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
"products": [
{
"auditDate": "2018-11-06T19:50:09",
"bathrooms": "2.5",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 1796,
"garagesNumber": "2",
"id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
"model": false,
"name": "Plan 2",
"newProduct": true,
"notAvailable": false,
"stories": 2
},
{
"auditDate": "2018-11-06T19:50:09",
"bathrooms": "3",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 2438,
"garagesNumber": "2",
"id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
"model": false,
"name": "Plan 5",
"newProduct": true,
"notAvailable": false,
"stories": 2
},
{
"auditDate": "2018-11-06T19:50:09",
"bathrooms": "4",
"bedrooms": "5",
"bestSeller": false,
"finishedSqFt": 2753,
"garagesNumber": "2",
"id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
"model": false,
"name": "Plan 6",
"newProduct": true,
"notAvailable": false,
"stories": 2
}
],
"seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
"userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"userName": "Lkolokousis@metrostudy.com"
},
"Optional("-LQgImKX4q5l9A-sTnuH")": {
"auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"dataEntryDevice": "iPad",
"dataEntryDeviceVersion": "0.9906",
"dateTimeUploaded": "2018-11-06T19:55:01",
"marketId": "19",
"metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
"products": [
{
"auditDate": "2018-11-06T19:55:01",
"bathrooms": "2.5",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 1796,
"garagesNumber": "2",
"id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
"model": false,
"name": "Plan 2",
"newProduct": true,
"notAvailable": true,
"stories": 2
},
{
"auditDate": "2018-11-06T19:55:01",
"bathrooms": "3",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 2438,
"garagesNumber": "2",
"id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
"model": false,
"name": "Plan 5",
"newProduct": true,
"notAvailable": true,
"stories": 2
},
{
"auditDate": "2018-11-06T19:55:01",
"bathrooms": "4",
"bedrooms": "5",
"bestSeller": false,
"finishedSqFt": 2753,
"garagesNumber": "2",
"id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
"model": false,
"name": "Plan 6",
"newProduct": true,
"notAvailable": true,
"stories": 2
}
],
"seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
"userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"userName": "Lkolokousis@metrostudy.com"
},
"Optional("-LQgL7xI2ZcYLV6LLXCO")": {
"auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"dataEntryDevice": "iPad",
"dataEntryDeviceVersion": "0.9906",
"dateTimeUploaded": "2018-11-06T20:05:18",
"marketId": "19",
"metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
"products": [
{
"auditDate": "2018-11-06T20:05:18",
"bathrooms": "2.5",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 1796,
"garagesNumber": "2",
"id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
"model": false,
"name": "Plan 2",
"newProduct": true,
"notAvailable": true,
"stories": 2,
"unitsReleased": 4,
"unitsRemaining": 0,
"unitsSold": 4
},
{
"auditDate": "2018-11-06T20:05:18",
"bathrooms": "3",
"bedrooms": "3",
"bestSeller": false,
"finishedSqFt": 2438,
"garagesNumber": "2",
"id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
"model": false,
"name": "Plan 5",
"newProduct": true,
"notAvailable": true,
"stories": 2,
"unitsReleased": 3,
"unitsRemaining": 0,
"unitsSold": 3
},
{
"auditDate": "2018-11-06T20:05:18",
"bathrooms": "4",
"bedrooms": "5",
"bestSeller": false,
"finishedSqFt": 2753,
"garagesNumber": "2",
"id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
"model": false,
"name": "Plan 6",
"newProduct": true,
"notAvailable": true,
"stories": 2,
"unitsReleased": 2,
"unitsRemaining": 0,
"unitsSold": 2
}
],
"seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
"userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
"userName": "Lkolokousis@metrostudy.com"
}
}
},
"subdivision": null,
"contact": null,
"salescenter": null
}


I need to loop through the nested products array and delete any element that has an empty id. I have tried some different things but cant find solution. Here is the last thign I tried.



 _seriesMaster.forEach((child) => {
if (child.key === 'products') {
child.forEach(x => {
x.val().products.forEach((p, i) => {
if (!p.id) {
x.val().products[i].remove()
}
})
})
}
})









share|improve this question





























    1















    I am trying to understand how to delete a node inside a snapshot. I have looked at other examples but I did not find something on deleting.



    this is what the JSON looks like



        {
    "series": {
    "audit": null,
    "contacts": null,
    "images": null,
    "products": {
    "-LQgKSWzEtN9eVHcVLzV": {
    "dataEntryDevice": "FIGGG",
    "dataEntryDeviceVersion": "1.0",
    "dateTimeUploaded": "2018-11-06T20:02:20-08:00",
    "marketId": 19,
    "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
    "products": [
    {
    "auditDate": "11/06/2018",
    "bathrooms": "",
    "bedrooms": "",
    "bestSeller": false,
    "garage": "",
    "id": "",
    "model": false,
    "name": "",
    "newProduct": false,
    "notAvailable": false,
    "price": 0,
    "stories": "",
    "unitsReleased": 0,
    "unitsSold": 0
    },
    {
    "auditDate": "11/06/2018",
    "bathrooms": "2.5",
    "bedrooms": "3",
    "bestSeller": false,
    "garage": "",
    "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
    "model": false,
    "name": "Plan 2",
    "newProduct": true,
    "notAvailable": true,
    "price": 0,
    "stories": 2,
    "unitsReleased": 4,
    "unitsSold": 4
    },
    {
    "auditDate": "11/06/2018",
    "bathrooms": "3",
    "bedrooms": "3",
    "bestSeller": false,
    "garage": "",
    "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
    "model": false,
    "name": "Plan 5",
    "newProduct": true,
    "notAvailable": true,
    "price": 0,
    "stories": 2,
    "unitsReleased": 3,
    "unitsSold": 3
    },
    {
    "auditDate": "11/06/2018",
    "bathrooms": "4",
    "bedrooms": "5",
    "bestSeller": false,
    "garage": "",
    "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
    "model": false,
    "name": "Plan 6",
    "newProduct": true,
    "notAvailable": true,
    "price": 0,
    "stories": 2,
    "unitsReleased": 2,
    "unitsSold": 2
    }
    ],
    "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
    "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26"
    },
    "Optional("-LQgHPWQ1KKElA8zWIKv")": {
    "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "dataEntryDevice": "iPad",
    "dataEntryDeviceVersion": "0.9906",
    "dateTimeUploaded": "2018-11-06T19:49:02",
    "marketId": "19",
    "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
    "products": [
    {
    "auditDate": "2018-11-06T19:49:02",
    "bathrooms": "2.5",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 1796,
    "garagesNumber": "2",
    "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
    "model": false,
    "name": "Plan 2",
    "newProduct": true,
    "notAvailable": false,
    "stories": 2
    }
    ],
    "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
    "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "userName": "Lkolokousis@metrostudy.com"
    },
    "Optional("-LQgHY12QubrBiwU0Uw7")": {
    "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "dataEntryDevice": "iPad",
    "dataEntryDeviceVersion": "0.9906",
    "dateTimeUploaded": "2018-11-06T19:49:36",
    "marketId": "19",
    "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
    "products": [
    {
    "auditDate": "2018-11-06T19:49:02",
    "bathrooms": "2.5",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 1796,
    "garagesNumber": "2",
    "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
    "model": false,
    "name": "Plan 2",
    "newProduct": true,
    "notAvailable": false,
    "stories": 2
    },
    {
    "auditDate": "2018-11-06T19:49:36",
    "bathrooms": "3",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 2438,
    "garagesNumber": "2",
    "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
    "model": false,
    "name": "Plan 5",
    "newProduct": true,
    "notAvailable": false,
    "stories": 2
    }
    ],
    "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
    "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "userName": "Lkolokousis@metrostudy.com"
    },
    "Optional("-LQgHeGVu075fgcbBWP7")": {
    "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "dataEntryDevice": "iPad",
    "dataEntryDeviceVersion": "0.9906",
    "dateTimeUploaded": "2018-11-06T19:50:06",
    "marketId": "19",
    "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
    "products": [
    {
    "auditDate": "2018-11-06T19:49:02",
    "bathrooms": "2.5",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 1796,
    "garagesNumber": "2",
    "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
    "model": false,
    "name": "Plan 2",
    "newProduct": true,
    "notAvailable": false,
    "stories": 2
    },
    {
    "auditDate": "2018-11-06T19:49:36",
    "bathrooms": "3",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 2438,
    "garagesNumber": "2",
    "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
    "model": false,
    "name": "Plan 5",
    "newProduct": true,
    "notAvailable": false,
    "stories": 2
    },
    {
    "auditDate": "2018-11-06T19:50:06",
    "bathrooms": "4",
    "bedrooms": "5",
    "bestSeller": false,
    "finishedSqFt": 2753,
    "garagesNumber": "2",
    "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
    "model": false,
    "name": "Plan 6",
    "newProduct": true,
    "notAvailable": false,
    "stories": 2
    }
    ],
    "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
    "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "userName": "Lkolokousis@metrostudy.com"
    },
    "Optional("-LQgHf1zpDDXs7m7KVNk")": {
    "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "dataEntryDevice": "iPad",
    "dataEntryDeviceVersion": "0.9906",
    "dateTimeUploaded": "2018-11-06T19:50:09",
    "marketId": "19",
    "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
    "products": [
    {
    "auditDate": "2018-11-06T19:50:09",
    "bathrooms": "2.5",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 1796,
    "garagesNumber": "2",
    "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
    "model": false,
    "name": "Plan 2",
    "newProduct": true,
    "notAvailable": false,
    "stories": 2
    },
    {
    "auditDate": "2018-11-06T19:50:09",
    "bathrooms": "3",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 2438,
    "garagesNumber": "2",
    "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
    "model": false,
    "name": "Plan 5",
    "newProduct": true,
    "notAvailable": false,
    "stories": 2
    },
    {
    "auditDate": "2018-11-06T19:50:09",
    "bathrooms": "4",
    "bedrooms": "5",
    "bestSeller": false,
    "finishedSqFt": 2753,
    "garagesNumber": "2",
    "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
    "model": false,
    "name": "Plan 6",
    "newProduct": true,
    "notAvailable": false,
    "stories": 2
    }
    ],
    "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
    "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "userName": "Lkolokousis@metrostudy.com"
    },
    "Optional("-LQgImKX4q5l9A-sTnuH")": {
    "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "dataEntryDevice": "iPad",
    "dataEntryDeviceVersion": "0.9906",
    "dateTimeUploaded": "2018-11-06T19:55:01",
    "marketId": "19",
    "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
    "products": [
    {
    "auditDate": "2018-11-06T19:55:01",
    "bathrooms": "2.5",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 1796,
    "garagesNumber": "2",
    "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
    "model": false,
    "name": "Plan 2",
    "newProduct": true,
    "notAvailable": true,
    "stories": 2
    },
    {
    "auditDate": "2018-11-06T19:55:01",
    "bathrooms": "3",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 2438,
    "garagesNumber": "2",
    "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
    "model": false,
    "name": "Plan 5",
    "newProduct": true,
    "notAvailable": true,
    "stories": 2
    },
    {
    "auditDate": "2018-11-06T19:55:01",
    "bathrooms": "4",
    "bedrooms": "5",
    "bestSeller": false,
    "finishedSqFt": 2753,
    "garagesNumber": "2",
    "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
    "model": false,
    "name": "Plan 6",
    "newProduct": true,
    "notAvailable": true,
    "stories": 2
    }
    ],
    "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
    "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "userName": "Lkolokousis@metrostudy.com"
    },
    "Optional("-LQgL7xI2ZcYLV6LLXCO")": {
    "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "dataEntryDevice": "iPad",
    "dataEntryDeviceVersion": "0.9906",
    "dateTimeUploaded": "2018-11-06T20:05:18",
    "marketId": "19",
    "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
    "products": [
    {
    "auditDate": "2018-11-06T20:05:18",
    "bathrooms": "2.5",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 1796,
    "garagesNumber": "2",
    "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
    "model": false,
    "name": "Plan 2",
    "newProduct": true,
    "notAvailable": true,
    "stories": 2,
    "unitsReleased": 4,
    "unitsRemaining": 0,
    "unitsSold": 4
    },
    {
    "auditDate": "2018-11-06T20:05:18",
    "bathrooms": "3",
    "bedrooms": "3",
    "bestSeller": false,
    "finishedSqFt": 2438,
    "garagesNumber": "2",
    "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
    "model": false,
    "name": "Plan 5",
    "newProduct": true,
    "notAvailable": true,
    "stories": 2,
    "unitsReleased": 3,
    "unitsRemaining": 0,
    "unitsSold": 3
    },
    {
    "auditDate": "2018-11-06T20:05:18",
    "bathrooms": "4",
    "bedrooms": "5",
    "bestSeller": false,
    "finishedSqFt": 2753,
    "garagesNumber": "2",
    "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
    "model": false,
    "name": "Plan 6",
    "newProduct": true,
    "notAvailable": true,
    "stories": 2,
    "unitsReleased": 2,
    "unitsRemaining": 0,
    "unitsSold": 2
    }
    ],
    "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
    "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
    "userName": "Lkolokousis@metrostudy.com"
    }
    }
    },
    "subdivision": null,
    "contact": null,
    "salescenter": null
    }


    I need to loop through the nested products array and delete any element that has an empty id. I have tried some different things but cant find solution. Here is the last thign I tried.



     _seriesMaster.forEach((child) => {
    if (child.key === 'products') {
    child.forEach(x => {
    x.val().products.forEach((p, i) => {
    if (!p.id) {
    x.val().products[i].remove()
    }
    })
    })
    }
    })









    share|improve this question



























      1












      1








      1








      I am trying to understand how to delete a node inside a snapshot. I have looked at other examples but I did not find something on deleting.



      this is what the JSON looks like



          {
      "series": {
      "audit": null,
      "contacts": null,
      "images": null,
      "products": {
      "-LQgKSWzEtN9eVHcVLzV": {
      "dataEntryDevice": "FIGGG",
      "dataEntryDeviceVersion": "1.0",
      "dateTimeUploaded": "2018-11-06T20:02:20-08:00",
      "marketId": 19,
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "11/06/2018",
      "bathrooms": "",
      "bedrooms": "",
      "bestSeller": false,
      "garage": "",
      "id": "",
      "model": false,
      "name": "",
      "newProduct": false,
      "notAvailable": false,
      "price": 0,
      "stories": "",
      "unitsReleased": 0,
      "unitsSold": 0
      },
      {
      "auditDate": "11/06/2018",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "garage": "",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": true,
      "price": 0,
      "stories": 2,
      "unitsReleased": 4,
      "unitsSold": 4
      },
      {
      "auditDate": "11/06/2018",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "garage": "",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": true,
      "price": 0,
      "stories": 2,
      "unitsReleased": 3,
      "unitsSold": 3
      },
      {
      "auditDate": "11/06/2018",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "garage": "",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": true,
      "price": 0,
      "stories": 2,
      "unitsReleased": 2,
      "unitsSold": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26"
      },
      "Optional("-LQgHPWQ1KKElA8zWIKv")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:49:02",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:49:02",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgHY12QubrBiwU0Uw7")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:49:36",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:49:02",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:49:36",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgHeGVu075fgcbBWP7")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:50:06",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:49:02",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:49:36",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:50:06",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "finishedSqFt": 2753,
      "garagesNumber": "2",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgHf1zpDDXs7m7KVNk")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:50:09",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:50:09",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:50:09",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:50:09",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "finishedSqFt": 2753,
      "garagesNumber": "2",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgImKX4q5l9A-sTnuH")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:55:01",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:55:01",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:55:01",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:55:01",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "finishedSqFt": 2753,
      "garagesNumber": "2",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgL7xI2ZcYLV6LLXCO")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T20:05:18",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T20:05:18",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2,
      "unitsReleased": 4,
      "unitsRemaining": 0,
      "unitsSold": 4
      },
      {
      "auditDate": "2018-11-06T20:05:18",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2,
      "unitsReleased": 3,
      "unitsRemaining": 0,
      "unitsSold": 3
      },
      {
      "auditDate": "2018-11-06T20:05:18",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "finishedSqFt": 2753,
      "garagesNumber": "2",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2,
      "unitsReleased": 2,
      "unitsRemaining": 0,
      "unitsSold": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      }
      }
      },
      "subdivision": null,
      "contact": null,
      "salescenter": null
      }


      I need to loop through the nested products array and delete any element that has an empty id. I have tried some different things but cant find solution. Here is the last thign I tried.



       _seriesMaster.forEach((child) => {
      if (child.key === 'products') {
      child.forEach(x => {
      x.val().products.forEach((p, i) => {
      if (!p.id) {
      x.val().products[i].remove()
      }
      })
      })
      }
      })









      share|improve this question
















      I am trying to understand how to delete a node inside a snapshot. I have looked at other examples but I did not find something on deleting.



      this is what the JSON looks like



          {
      "series": {
      "audit": null,
      "contacts": null,
      "images": null,
      "products": {
      "-LQgKSWzEtN9eVHcVLzV": {
      "dataEntryDevice": "FIGGG",
      "dataEntryDeviceVersion": "1.0",
      "dateTimeUploaded": "2018-11-06T20:02:20-08:00",
      "marketId": 19,
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "11/06/2018",
      "bathrooms": "",
      "bedrooms": "",
      "bestSeller": false,
      "garage": "",
      "id": "",
      "model": false,
      "name": "",
      "newProduct": false,
      "notAvailable": false,
      "price": 0,
      "stories": "",
      "unitsReleased": 0,
      "unitsSold": 0
      },
      {
      "auditDate": "11/06/2018",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "garage": "",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": true,
      "price": 0,
      "stories": 2,
      "unitsReleased": 4,
      "unitsSold": 4
      },
      {
      "auditDate": "11/06/2018",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "garage": "",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": true,
      "price": 0,
      "stories": 2,
      "unitsReleased": 3,
      "unitsSold": 3
      },
      {
      "auditDate": "11/06/2018",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "garage": "",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": true,
      "price": 0,
      "stories": 2,
      "unitsReleased": 2,
      "unitsSold": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26"
      },
      "Optional("-LQgHPWQ1KKElA8zWIKv")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:49:02",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:49:02",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgHY12QubrBiwU0Uw7")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:49:36",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:49:02",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:49:36",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgHeGVu075fgcbBWP7")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:50:06",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:49:02",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:49:36",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:50:06",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "finishedSqFt": 2753,
      "garagesNumber": "2",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgHf1zpDDXs7m7KVNk")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:50:09",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:50:09",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:50:09",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:50:09",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "finishedSqFt": 2753,
      "garagesNumber": "2",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": false,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgImKX4q5l9A-sTnuH")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T19:55:01",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T19:55:01",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:55:01",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2
      },
      {
      "auditDate": "2018-11-06T19:55:01",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "finishedSqFt": 2753,
      "garagesNumber": "2",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      },
      "Optional("-LQgL7xI2ZcYLV6LLXCO")": {
      "auditorUserId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "dataEntryDevice": "iPad",
      "dataEntryDeviceVersion": "0.9906",
      "dateTimeUploaded": "2018-11-06T20:05:18",
      "marketId": "19",
      "metrostudyMarketId": "D245B426-102C-4678-BED2-BB9FB35764BD",
      "products": [
      {
      "auditDate": "2018-11-06T20:05:18",
      "bathrooms": "2.5",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 1796,
      "garagesNumber": "2",
      "id": "AFF1EE66-578C-4DA0-90A2-B9F447EA52B6",
      "model": false,
      "name": "Plan 2",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2,
      "unitsReleased": 4,
      "unitsRemaining": 0,
      "unitsSold": 4
      },
      {
      "auditDate": "2018-11-06T20:05:18",
      "bathrooms": "3",
      "bedrooms": "3",
      "bestSeller": false,
      "finishedSqFt": 2438,
      "garagesNumber": "2",
      "id": "0059ED00-102C-48D9-95E0-E68A04D2E877",
      "model": false,
      "name": "Plan 5",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2,
      "unitsReleased": 3,
      "unitsRemaining": 0,
      "unitsSold": 3
      },
      {
      "auditDate": "2018-11-06T20:05:18",
      "bathrooms": "4",
      "bedrooms": "5",
      "bestSeller": false,
      "finishedSqFt": 2753,
      "garagesNumber": "2",
      "id": "08CEF557-EDF7-46E7-AC9B-A380E2046616",
      "model": false,
      "name": "Plan 6",
      "newProduct": true,
      "notAvailable": true,
      "stories": 2,
      "unitsReleased": 2,
      "unitsRemaining": 0,
      "unitsSold": 2
      }
      ],
      "seriesId": "5571E356-AEE5-443A-AC45-47661EB99096",
      "userId": "395a2c10-6d7e-41d9-92cd-0704caf5eb26",
      "userName": "Lkolokousis@metrostudy.com"
      }
      }
      },
      "subdivision": null,
      "contact": null,
      "salescenter": null
      }


      I need to loop through the nested products array and delete any element that has an empty id. I have tried some different things but cant find solution. Here is the last thign I tried.



       _seriesMaster.forEach((child) => {
      if (child.key === 'products') {
      child.forEach(x => {
      x.val().products.forEach((p, i) => {
      if (!p.id) {
      x.val().products[i].remove()
      }
      })
      })
      }
      })






      javascript firebase firebase-realtime-database






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 '18 at 20:43









      Doug Stevenson

      73.2k984105




      73.2k984105










      asked Nov 17 '18 at 20:27









      texas697texas697

      85184291




      85184291
























          1 Answer
          1






          active

          oldest

          votes


















          2














          You treat it as an array, so first filter it:



          const filteredProducts = x.val().products.filter(p => !p.id)


          and then set the node with filteredProducts



          const productUID = x.key;
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)


          Full solution:



          _seriesMaster.forEach((child) => {
          if (child.key === 'products') {
          child.forEach(x => {
          const productUID = x.key;
          const filteredProducts = x.val().products.filter(p => !p.id)
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)
          })
          }
          })





          share|improve this answer


























          • This is indeed the correct approach with OPs current data structure. Note that the Firebase documentation typically recommends against using arrays for such list structure. For some of the reasons, see firebase.googleblog.com/2014/04/…

            – Frank van Puffelen
            Nov 17 '18 at 20:47











          • how do I get the productUID

            – texas697
            Nov 17 '18 at 20:52











          • x.key should be your productUID

            – MrAleister
            Nov 17 '18 at 21:09











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355262%2fhow-to-manipulate-firebase-snapshot-data%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          You treat it as an array, so first filter it:



          const filteredProducts = x.val().products.filter(p => !p.id)


          and then set the node with filteredProducts



          const productUID = x.key;
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)


          Full solution:



          _seriesMaster.forEach((child) => {
          if (child.key === 'products') {
          child.forEach(x => {
          const productUID = x.key;
          const filteredProducts = x.val().products.filter(p => !p.id)
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)
          })
          }
          })





          share|improve this answer


























          • This is indeed the correct approach with OPs current data structure. Note that the Firebase documentation typically recommends against using arrays for such list structure. For some of the reasons, see firebase.googleblog.com/2014/04/…

            – Frank van Puffelen
            Nov 17 '18 at 20:47











          • how do I get the productUID

            – texas697
            Nov 17 '18 at 20:52











          • x.key should be your productUID

            – MrAleister
            Nov 17 '18 at 21:09
















          2














          You treat it as an array, so first filter it:



          const filteredProducts = x.val().products.filter(p => !p.id)


          and then set the node with filteredProducts



          const productUID = x.key;
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)


          Full solution:



          _seriesMaster.forEach((child) => {
          if (child.key === 'products') {
          child.forEach(x => {
          const productUID = x.key;
          const filteredProducts = x.val().products.filter(p => !p.id)
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)
          })
          }
          })





          share|improve this answer


























          • This is indeed the correct approach with OPs current data structure. Note that the Firebase documentation typically recommends against using arrays for such list structure. For some of the reasons, see firebase.googleblog.com/2014/04/…

            – Frank van Puffelen
            Nov 17 '18 at 20:47











          • how do I get the productUID

            – texas697
            Nov 17 '18 at 20:52











          • x.key should be your productUID

            – MrAleister
            Nov 17 '18 at 21:09














          2












          2








          2







          You treat it as an array, so first filter it:



          const filteredProducts = x.val().products.filter(p => !p.id)


          and then set the node with filteredProducts



          const productUID = x.key;
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)


          Full solution:



          _seriesMaster.forEach((child) => {
          if (child.key === 'products') {
          child.forEach(x => {
          const productUID = x.key;
          const filteredProducts = x.val().products.filter(p => !p.id)
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)
          })
          }
          })





          share|improve this answer















          You treat it as an array, so first filter it:



          const filteredProducts = x.val().products.filter(p => !p.id)


          and then set the node with filteredProducts



          const productUID = x.key;
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)


          Full solution:



          _seriesMaster.forEach((child) => {
          if (child.key === 'products') {
          child.forEach(x => {
          const productUID = x.key;
          const filteredProducts = x.val().products.filter(p => !p.id)
          const path = 'series/products/' + productUID + '/products';
          firebase.database().ref(path).set(filteredProducts)
          })
          }
          })






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 17 '18 at 21:11

























          answered Nov 17 '18 at 20:46









          MrAleisterMrAleister

          439210




          439210













          • This is indeed the correct approach with OPs current data structure. Note that the Firebase documentation typically recommends against using arrays for such list structure. For some of the reasons, see firebase.googleblog.com/2014/04/…

            – Frank van Puffelen
            Nov 17 '18 at 20:47











          • how do I get the productUID

            – texas697
            Nov 17 '18 at 20:52











          • x.key should be your productUID

            – MrAleister
            Nov 17 '18 at 21:09



















          • This is indeed the correct approach with OPs current data structure. Note that the Firebase documentation typically recommends against using arrays for such list structure. For some of the reasons, see firebase.googleblog.com/2014/04/…

            – Frank van Puffelen
            Nov 17 '18 at 20:47











          • how do I get the productUID

            – texas697
            Nov 17 '18 at 20:52











          • x.key should be your productUID

            – MrAleister
            Nov 17 '18 at 21:09

















          This is indeed the correct approach with OPs current data structure. Note that the Firebase documentation typically recommends against using arrays for such list structure. For some of the reasons, see firebase.googleblog.com/2014/04/…

          – Frank van Puffelen
          Nov 17 '18 at 20:47





          This is indeed the correct approach with OPs current data structure. Note that the Firebase documentation typically recommends against using arrays for such list structure. For some of the reasons, see firebase.googleblog.com/2014/04/…

          – Frank van Puffelen
          Nov 17 '18 at 20:47













          how do I get the productUID

          – texas697
          Nov 17 '18 at 20:52





          how do I get the productUID

          – texas697
          Nov 17 '18 at 20:52













          x.key should be your productUID

          – MrAleister
          Nov 17 '18 at 21:09





          x.key should be your productUID

          – MrAleister
          Nov 17 '18 at 21:09


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355262%2fhow-to-manipulate-firebase-snapshot-data%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?