Skip to content

Commit

Permalink
script to soft delet TSR hub documents
Browse files Browse the repository at this point in the history
  • Loading branch information
per305 authored and per305 committed Apr 29, 2022
1 parent 547940e commit 1d2a854
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions scripts/RestClient/nesp/cleanNespDocuments.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
var projectIdArr = ['c713e4f1-c57f-4040-9093-24f9aed39ac5','17e82227-aee5-4fbf-adaa-50a0469847e7']
// This script will soft delete existing NESP TSR hub's documents

var projectIdArr = ['d748bd95-0b4d-450c-8fa4-20a7bcfd9c19','08e07841-764c-4fcd-8bbc-7dc38e6fbd5f']

db.document.update({$and:[{"projectId": {$in: projectIdArr}},{"contentType": "application/pdf"}]},{$set:{"status": "deleted"}},{multi: true})

This comment has been minimized.

Copy link
@temi

temi Apr 29, 2022

Contributor

print how many documents were modified as result of this operation. and compare with the below find query result.


var documents = db.document.find({"projectId":{$in:projectIdArr}})

This comment has been minimized.

Copy link
@temi

temi Apr 29, 2022

Contributor

does not match above condition. missing pdf check.


var document = ""
var projectId = ""
var documentId = ""
var path = ""
var record = ""
var doc = "";
var documentId = "";
var filepath = "";
var filename = "";

var rows = []
print("DOCUMENT ID, FULL PATH");

while (documents.hasNext()) {
document = documents.next();

projectId = document.projectId;
documentId = document.documentId;
path = document.filepath;

record = projectId + "," + documentId + "," + path

rows.push(record)
}

let csvContent = "data:text/csv;charset=utf-8,";

rows.forEach(function(row) {
csvContent += row.join(',');
csvContent += "\n";
});
filepath = "/data/ecodata/uploads/"

console.log(csvContent);
doc = documents.next();

var encodedUri = encodeURI(csvContent);
window.open(encodedUri);
documentId = doc.documentId;
filename = doc.filename;
filepath += doc.filepath + "/" + filename;

print("documentResult"+documentResult)
print(documentId+", "+filepath);
}

0 comments on commit 1d2a854

Please sign in to comment.