<p>I am trying to backup a database from a kubernetes cluster to my computer as a bson file. I have connected my mongodb compass to the kubernetes cluster using port-forwarding. Can anyone help me with the command I need to download a particular Collection (450gb) from a databank to my desktop?</p>
<p>I've been trying for a while now but I cant seem to find the way around it.</p>
<p>In mongocompass there is unfortunately no way to download a collection as a bson file.
The port I have forwarded the kubernetes pod to is 27017.</p>

<p>From the mongodb official docs:</p>
<blockquote>
<p>Run  <a href="https://docs.mongodb.com/database-tools/mongodump/#mongodb-binary-bin.mongodump" rel="nofollow noreferrer"><code>mongodump</code></a>  from the system command line, not the  <a href="https://docs.mongodb.com/manual/reference/program/mongo/#mongodb-binary-bin.mongo" rel="nofollow noreferrer"><code>mongo</code></a>  shell.</p>
</blockquote>
<p>So, assuming you configured <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="nofollow noreferrer">Kubernetes Port Forwarding</a> on your <strong>local machine</strong> like this:</p>
<pre><code>$ kubectl port-forward service/mongo 28015:27017
</code></pre>
<p>And you've got output similar to this:</p>
<pre class="lang-yaml prettyprint-override"><code>Forwarding from 127.0.0.1:28015 -&gt; 27017
Forwarding from [::1]:28015 -&gt; 27017
</code></pre>
<p>You can now export data from mongodb using the following command:</p>
<pre><code>$ mongodump --username root --port=28015 -p secretpassword
</code></pre>
<p>This will create a <code>dump</code> directory in the current working directory and export data there.</p>
<p>Also, to export only specific collection use the following option:</p>
<pre><code>--collection=&lt;collection&gt;, -c=&lt;collection&gt;
</code></pre>
<blockquote>
<p>Specifies a collection to backup. If you do not specify a collection, this option copies all collections in the specified database or instance to the dump files.</p>
</blockquote>
<p>You can check other available option <a href="https://docs.mongodb.com/database-tools/mongodump/" rel="nofollow noreferrer">here</a>.</p>
