Export MongoDB Query to a file
<p>I have a MongoDB query which returns a set of single level BSON objects.</p>

<pre><code>db.companies.aggregate([
    { $unwind: {
        path: "$addresses", includeArrayIndex: "arrayIndex"}
    },
    { $project: {
        hrId:1, 
        arrayIndex:1,
        location:'$addresses.location', 
        street:'$addresses.street', 
        city:'$addresses.city', 
        state:'$addresses.state', 
        country:'$addresses.country', 
        postCode:'$addresses.postCode'} 
    }])
</code></pre>

<p>I want to export this to a csv file. I have been looking online for a simple solution but to no avail. I am happy to use a gui/tool to do this if required.</p>

<p>Thanks in advance for your help </p>