How to manipulate firebase snapshot data
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
add a comment |
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
add a comment |
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
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
javascript firebase firebase-realtime-database
edited Nov 17 '18 at 20:43
Doug Stevenson
73.2k984105
73.2k984105
asked Nov 17 '18 at 20:27
texas697texas697
85184291
85184291
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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)
})
}
})
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
})
}
})
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
add a comment |
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)
})
}
})
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
add a comment |
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)
})
}
})
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)
})
}
})
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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