I wanted to see if I’m able to begin writing csv files locally using a query that I use in intellishell, but not sure how to change the path to where I can write locally after querying a live connection in studio 3t. I’ve also tried using “process.chdr()” , to no avail (output of intellishell output when trying to change directory).
Here’s an example of the code I’m trying to get to work to write locally, while connected live to a mongo db:
const startDate = ISODate(“2023-03-28”);
const endDate = ISODate(“2023-03-29”);
const cursor = db.getCollection(“yo_mama_db”).aggregate([
{ $match: { “createdDateTime”: { $gte: startDate, $lt: endDate }, “holdStatus”: {$exists:true} } },
{ $project:
{
createdDateTime: { $ifNull: [“$createdDateTime”,“”] },
ID: { $ifNull: [“$_id”,“”] },
xyz: { $ifNull: [“$document.record.xyz”,“”] },
}},
]);
let output = “”;
cursor.forEach(function (row) {
if (output.length === 0) {
output += Object.keys(row).join(“,”) + “\n”;
}
output += Object.values(row).map(value => value instanceof Date ? value.toISOString() : (value === null ? “” : value)).join(“,”) + “\n”;
});
const filePath = “C:\Users\localpath”;
const file = new File(filePath);
file.open(“w”);
file.write(output);
file.close();
Thanks for the help - Alex