Skip to content

Commit

Permalink
update deleted doc records
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaytkbabu committed Sep 7, 2023
1 parent af1f999 commit 3b72997
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions api/migrations/20230901215837-updateDeletedDocRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,35 @@ exports.up = async function(db) {


const redactedCollection = await mClient.collection(redactedCollectionName);
const nrptiCollection = await mClient.collection(nrptiCollectionName);
//const nrptiCollection = await mClient.collection(nrptiCollectionName);



// Subquery to find _id values with schema 'Document' in both collections
const subquery = [
{ _schemaName: 'Document' },
{ _schemaName: 'Document' }
];
// const subquery = [
// { _schemaName: 'Document' },
// { _schemaName: 'Document' }
// ];

const collectionResults = await redactedCollection.find({ $or: subquery }, { _id: 1 }).toArray();
// const collectionResults = await redactedCollection.find({ $or: subquery }, { _id: 1 }).toArray();

const nrptiResults = await nrptiCollection.find({ $or: subquery }, { _id: 1 }).toArray();
// const nrptiResults = await nrptiCollection.find({ $or: subquery }, { _id: 1 }).toArray();



console.log('inthen>>>>>')
//console.log('inthen>>>>>')
// Extract _id values from the subquery results
const validIds = [...new Set([...collectionResults, ...nrptiResults].map(item => item._id))];
//const validIds = [...new Set([...collectionResults, ...nrptiResults].map(item => item._id))];

let redactedDocumentsIds = await redactedCollection.find({_schemaName: 'Document'}).toArray();
redactedDocumentsIds=redactedDocumentsIds.map(item => item._id);

console.log('validIds= ' + validIds.length)
//console.log('validIdsCount= ' + validIds.length)

console.log('redactedCount= ' + redactedDocumentsIds.length)

console.log('redacted1=' + redactedDocumentsIds[0]);
console.log('redacted2=' + redactedDocumentsIds[1]);

const cursor = redactedCollection.find({
"documents": { "$exists": true, "$not": { "$size": 0 } }
Expand All @@ -66,16 +70,23 @@ let ct = 0;
await cursor.forEach(record => {
if(!redactedDocumentsIds.includes(record['documents'][0]))
{
console.log('in_if' + ct)
redactedCollection.updateOne(
{_id: record._id},
{$set: {documents: []}}
)
console.log('in_if' + ct + 'documentid=' + record['documents'][0])
// redactedCollection.updateOne(
// {_id: record._id},
// {$set: {documents: []}}
// )
}
else{
console.log('in_else' + ct)
console.log('in_else' + ct)
}

// const foundElement = redactedDocumentsIds.some(item => item === record['documents'][0]);
// if (foundElement === undefined) {
// // Element not found
// // console.log('in_if' + ct + 'documentid=' + record['documents'][0])
// }
// else{
// console.log('in_else' + ct + 'documentid=' + record['documents'][0])
// }
ct++;


Expand Down

0 comments on commit 3b72997

Please sign in to comment.