Skip to main content

Mongo CSV Export

Using mongoexport, we can generate reports and export to a csv file.

[{$match: {
job_run_id: '1632404655334_1635181922992'
}}, {$lookup: {
from: 'tsMappingAudits',
localField: 'job_run_id',
foreignField: 'jobRunId',
as: 'properties'
}}, {$addFields: {
properties: {
$filter: {
input: '$properties',
as: 'props',
cond: {
$eq: [
'$$props.docId',
'$doc_id'
]
}
}
}
}}]

Mongo Export of ALL records with any PII

mongoexport --db simflofy --collection tsRecordProcessed--fields
doc_id,doc_name,auditFields.pii.pii --query '{"auditFields.pii.pii" :
{$exists:true},$where:"this.auditFields.pii.pii.length > 0"}' --type=csv --out
pii.csv

Mongo Export of only those records with Social Security + Name PII

mongoexport --db simflofy --collection tsRecordProcessed--fields
doc_id,doc_name,auditFields.pii.pii --query '{$and:[{"auditFields.pii.pii" :
"SocialSecurity"},{"auditFields.pii.pii" : "Name"}]}' --type=csv --out
ssn_name_pii.csv

Mongo Export all records from a specific job

.mongoexport.exe --db=simflofy --collection=tsRecordProcessed --type=csv
--fields=doc_id,doc_name,new_id,job_run_id --out=processed.csv
--query="{'job_run_id':{'$eq':'1499299208621_1499303089056'}}"

Example json dump of the properties you can select in the --fields option:

{  
"_id" : ObjectId("595d8cb2b2d79824fc3a40a0"),
"new_id" : "dea46b6d-3ee4-4e4c-aa0d-dfbd6bd90c1c",
"createdDate" : ISODate("2017-07-06T01:04:50.229Z"),
"job_name" : "File System to Nuxeo",
"job_run_id" : "1499299208621_1499303089056",
"doc_name" : "atom.metadata.properties.xml",
"job_id" : NumberLong("1499299208621"),
"docHash" : null,
"doc_type" : "File",
"doc_uri" : "D:\test\documents\atom.metadata.properties.xml",
"doc_id" : "D:\test\documents\atom.metadata.properties.xml",
"content_length" : NumberLong(222)
}