Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Pr #139

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
let updatedProjectIds = [];
let deletedSolutionIds = [];
let deletedProgramIds = [];
let skipedProjects = [];
let errorProject=[];



//get all projectss id where user profile is not there.
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);
Expand All @@ -53,7 +55,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++) {

Expand All @@ -64,13 +66,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" : {}
Expand Down Expand Up @@ -119,17 +122,27 @@
deletedSolutionIds.push(projectDocuments[counter].solutionId)
deletedProgramIds.push(projectDocuments[counter].programId)

// update project documents
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
})
// 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)
skipedProjects.push(projectDocuments[counter]._id)
errorProject.push(JSON.stringify(err))
}


}
}
}
Expand All @@ -145,7 +158,7 @@
fs.writeFile(
'updatedProjectIdsAll.json',

JSON.stringify({updatedProjectIds: updatedProjectIds,deletedProgramIds: deletedProgramIds,deletedSolutionIds: deletedSolutionIds}),
JSON.stringify({updatedProjectIds: updatedProjectIds,deletedProgramIds: deletedProgramIds,deletedSolutionIds: deletedSolutionIds,skipedProjects:skipedProjects,errorProject: errorProject}),

function (err) {
if (err) {
Expand All @@ -157,6 +170,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();
}
Expand Down