From 8aa87c68ebd9b72f30dd557bd7303f5c9ca9d505 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Feb 2023 12:40:36 +0530 Subject: [PATCH 1/4] Updated Pr --- .../migratePrivateProjectToPublicProgram.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js b/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js index 1a5866df..97f0b17f 100644 --- a/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js +++ b/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js @@ -35,7 +35,7 @@ let projectDocument = await db.collection('projects').find({ userRoleInformation: {$exists : false}, isAPrivateProgram: true, - }).project({_id:1,userProfile:1}).toArray(); + }).project({_id:1}).toArray(); let chunkOfProjectDocument = _.chunk(projectDocument, 10); @@ -53,7 +53,7 @@ // get project documents from projectss collection in Array let projectDocuments = await db.collection('projects').find({ _id: { $in :projectIds } - }).project({_id:1,userProfile:1}).toArray(); + }).project({}).toArray(); //iterate project documents one by one for(let counter = 0; counter < projectDocuments.length; counter++) { @@ -64,13 +64,14 @@ _id: projectDocuments[counter].solutionId, parentSolutionId : {$exists:true}, isAPrivateProgram : true - }).project({}).toArray({}) + }).project({parentSolutionId:1}).toArray({}) //find program document form program collection if(solutionDocument.length == 1){ // find parent solution document in same collection let parentSolutionDocument = await db.collection('solutions').find({ _id: solutionDocument[0].parentSolutionId}).project({}).toArray({}); + //varibale to update project document let updateProjectDocument = { "$set" : {} @@ -120,6 +121,7 @@ deletedProgramIds.push(projectDocuments[counter].programId) // update project documents + await db.collection('projects').findOneAndUpdate({ "_id" : projectDocuments[counter]._id },updateProjectDocument); @@ -130,6 +132,7 @@ await db.collection('programs').deleteOne({ _id: projectDocuments[counter].programId }) + } } } From b487dca44cfeb5544b925d02ee58f8e202285884 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Feb 2023 16:14:43 +0530 Subject: [PATCH 2/4] added try catch if it fails while updating document --- .../migratePrivateProjectToPublicProgram.js | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js b/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js index 97f0b17f..ba2f6bd8 100644 --- a/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js +++ b/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js @@ -120,19 +120,25 @@ deletedSolutionIds.push(projectDocuments[counter].solutionId) deletedProgramIds.push(projectDocuments[counter].programId) - // update project documents + // update project documents + try{ + await db.collection('projects').findOneAndUpdate({ + "_id" : projectDocuments[counter]._id + },updateProjectDocument); + + await db.collection('solutions').deleteOne({ + _id: projectDocuments[counter].solutionId + }) + await db.collection('programs').deleteOne({ + _id: projectDocuments[counter].programId + }) + + + }catch(err){ + console.log(err) + } - await db.collection('projects').findOneAndUpdate({ - "_id" : projectDocuments[counter]._id - },updateProjectDocument); - - await db.collection('solutions').deleteOne({ - _id: projectDocuments[counter].solutionId - }) - await db.collection('programs').deleteOne({ - _id: projectDocuments[counter].programId - }) - + } } } From fe245dac1e259ac4076f214a5893d6f784204f08 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Feb 2023 16:20:11 +0530 Subject: [PATCH 3/4] Added skiped projectIds --- .../migratePrivateProjectToPublicProgram.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js b/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js index ba2f6bd8..94a766a9 100644 --- a/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js +++ b/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js @@ -28,6 +28,7 @@ let updatedProjectIds = []; let deletedSolutionIds = []; let deletedProgramIds = []; + let skipedProjects = [] @@ -136,6 +137,7 @@ }catch(err){ console.log(err) + skipedProjects.push(projectDocuments[counter]._id) } @@ -154,7 +156,7 @@ fs.writeFile( 'updatedProjectIdsAll.json', - JSON.stringify({updatedProjectIds: updatedProjectIds,deletedProgramIds: deletedProgramIds,deletedSolutionIds: deletedSolutionIds}), + JSON.stringify({updatedProjectIds: updatedProjectIds,deletedProgramIds: deletedProgramIds,deletedSolutionIds: deletedSolutionIds,skipedProjects:skipedProjects}), function (err) { if (err) { @@ -166,6 +168,7 @@ console.log("Updated Project Count : ", updatedProjectIds.length) console.log("deleted program Count : ", deletedProgramIds.length) console.log("deleted solutionId Count : ", deletedSolutionIds.length) + console.log("skiped project Count : ", skipedProjects.length) console.log("completed") connection.close(); } From 203600027b5b694f5b3434541fe58460a2824865 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Feb 2023 16:22:16 +0530 Subject: [PATCH 4/4] Added errors as well --- .../migratePrivateProjectToPublicProgram.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js b/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js index 94a766a9..afc3b738 100644 --- a/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js +++ b/migrations/updateProjectDocuments/migratePrivateProjectToPublicProgram.js @@ -28,7 +28,8 @@ let updatedProjectIds = []; let deletedSolutionIds = []; let deletedProgramIds = []; - let skipedProjects = [] + let skipedProjects = []; + let errorProject=[]; @@ -138,6 +139,7 @@ }catch(err){ console.log(err) skipedProjects.push(projectDocuments[counter]._id) + errorProject.push(JSON.stringify(err)) } @@ -156,7 +158,7 @@ fs.writeFile( 'updatedProjectIdsAll.json', - JSON.stringify({updatedProjectIds: updatedProjectIds,deletedProgramIds: deletedProgramIds,deletedSolutionIds: deletedSolutionIds,skipedProjects:skipedProjects}), + JSON.stringify({updatedProjectIds: updatedProjectIds,deletedProgramIds: deletedProgramIds,deletedSolutionIds: deletedSolutionIds,skipedProjects:skipedProjects,errorProject: errorProject}), function (err) { if (err) {