<p>In Detail, the .JS file contains MongoDB commands like below,</p>
<pre class="lang-js prettyprint-override"><code>db = db.getSiblingDB('records')
db.createCollection(&quot;collection_new&quot;);
db.collection_new.insertMany([
  { capped : true, size : 5242880, max : 5000 },
  { capped : false, size : 5242880, max : 8000 },
  { capped : false, size : 5242880, max : 5000 },
  { capped : true, size : 5242880, max : 8000 }
 ])
</code></pre>
<p>Now, instead of converting this .JS file into a standalone .yaml configmap file, I want to create a configmap which refers to the .JS file. Also, I do not want to add the raw data inside the configmap because the above commands are just a small part of the JS file. The main file contains approx. 400-500 lines.</p>

<p>You cannot make reference to a file from a configmap. As suggested in the comments, you can use an <a href="https://docs.helm.sh/docs/chart_template_guide/accessing_files/" rel="nofollow noreferrer">Helm template which make reference to a file</a>:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: my-configmap
data:
  mongo-commands.js: |-
    {{ .Files.Get &quot;js/mongo_commands.js&quot; }}
</code></pre>
<p>Note that:</p>
<ul>
<li>The directory <code>js</code> is at the root of the Helm chart.</li>
<li>Charts must be smaller than 1M because of the storage limitations of Kubernetes objects.</li>
<li>Files in templates/ cannot be accessed.</li>
<li>Files excluded using <code>.helmignore</code> cannot be accessed.</li>
</ul>
