diff --git a/api/migrations/20230901215837-updateDeletedDocRecords.js b/api/migrations/20230901215837-updateDeletedDocRecords.js index b9cbb8cd4..00bbc18ad 100644 --- a/api/migrations/20230901215837-updateDeletedDocRecords.js +++ b/api/migrations/20230901215837-updateDeletedDocRecords.js @@ -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 } } @@ -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++;