Closed drfaustusfade closed 4 years ago
// correct cluster db.getCollection("beneficiaries").find({admin0pcode:"AF", report_year: 2019}).forEach(function(d){ // print('activity:',d.activity_description_id) var a = db.getCollection("activities").findOne({admin0pcode: {$regex: d.admin0pcode}, activity_description_id: d.activity_description_id}); // if (a) print('found:', a.activity_description_id) if (!a) print('missing:', d.report_id, d.activity_description_id, d.cluster_id) if (a && a.cluster_id !== d.cluster_id) { print( 'update:', d.report_id, d.activity_description_id, d.cluster_id, a.cluster_id ); d.cluster_id = a.cluster_id; d.cluster = a.cluster; db.getCollection("beneficiaries").save(d); } });
// clean data that should not contain mpc related attribute values db.getCollection("beneficiaries").find({admin0pcode:"AF", report_year: 2019}).forEach(function(d){ var a = db.getCollection("activities").findOne({admin0pcode: {$regex: d.admin0pcode}, activity_description_id: d.activity_description_id}); if (!a) print('step3', d.report_id, d.activity_description_id, d.cluster_id) if (a && d.mpc_delivery_type_id && !a.mpc_delivery_type_id) { print ('mpc_delivery_type_id', d.activity_description_id, d.mpc_delivery_type_id, d.report_id, d._id) delete d.mpc_delivery_type_id; delete d.mpc_delivery_type_id; db.getCollection("beneficiaries").save(d); } if (a && d.mpc_mechanism_type_id && !a.mpc_mechanism_type_id) { print ('mpc_mechanism_type_id', d.activity_description_id, d.mpc_mechanism_type_id, d.report_id, d._id); delete d.mpc_mechanism_type_id; delete d.mpc_mechanism_type_name; db.getCollection("beneficiaries").save(d); } if (a && d.package_type_id && !a.mpc_package_type_id) { print ('mpc_package_type_id', d.activity_description_id, d.package_type_id, d.report_id, d._id); delete d.package_type_id; delete d.package_type_name; db.getCollection("beneficiaries").save(d); } if (a && d.transfer_type_id && !a.mpc_transfer_type_id) { print ('mpc_transfer_type_id', d.activity_description_id, d.transfer_type_id, d.report_id, d._id); delete d.transfer_type_id; delete d.transfer_type_name; delete d.transfer_type_value; db.getCollection("beneficiaries").save(d); } });
https://github.com/pfitzpaddy/ngm-reportHub/pull/314