<p>I need to create kubernetes job that will run below script on mongo shell:</p>
<pre><code>var operations = [];
db.product.find().forEach(function(doc) {
    var documentLink = doc.documentLink; 
    var operation = { updateMany :{ 
&quot;filter&quot; : {&quot;_id&quot; : doc._id},
&quot;update&quot; : {$set:{&quot;documentLinkMap.en&quot;:documentLink,&quot;documentLinkMap.de&quot;:&quot;&quot;},
    $unset: {documentLink:&quot;&quot;,&quot;descriptionMap.tr&quot;:&quot;&quot;,&quot;news.tr&quot;:&quot;&quot;,&quot;descriptionInternal.tr&quot;:&quot;&quot;,&quot;salesDescription.tr&quot;:&quot;&quot;,&quot;salesInternal.tr&quot;:&quot;&quot;,&quot;deliveryDescription.tr&quot;:&quot;&quot;,&quot;deliveryInternal.tr&quot;:&quot;&quot;,&quot;productRoadMapDescription.tr&quot;:&quot;&quot;,&quot;productRoadMapInternal.tr&quot;:&quot;&quot;,&quot;technicalsAndIntegration.tr&quot;:&quot;&quot;,&quot;technicalsAndIntegrationInternal.tr&quot;:&quot;&quot;,&quot;versions.$[].descriptionMap.tr&quot;:&quot;&quot;,&quot;versions.$[].releaseNoteMap.tr&quot;:&quot;&quot;,&quot;versions.$[].artifacts.$[].descriptionMap.tr&quot;:&quot;&quot;,&quot;versions.$[].artifacts.$[].artifactNotes.tr&quot;:&quot;&quot;}}}};
    operations.push(operation); 
});
operations.push( {
    ordered: true,      
    writeConcern: { w: &quot;majority&quot;, wtimeout: 5000 } 
});
db.product.bulkWrite(operations);
</code></pre>
<p>I will need a sample of how that job will look like. Should I create presistent volume and claim to it or is there possibility to run this job without persistent volume? I need to run this once and then remove it.</p>

kemoT
<p>You can solve it much easier with <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer"><code>configMap</code></a> and then mount the <code>configMap</code> as a volume which will be resolved in a file.</p>
<p>Below is example how to proceed with it (Note! You will need to use a proper image for it as well as some other changes how mongo shell works):</p>
<ol>
<li><p>Create a <code>configMap</code> from file. Can be done by running this command:</p>
<pre><code>$ kubectl create cm mongoscript-cm --from-file=mongoscript.js
configmap/mongoscript-cm created
</code></pre>
<p>You can check that you file is stored inside by running:</p>
<pre><code>$ kubectl describe cm mongoscript-cm
</code></pre>
</li>
<li><p>Create a job with volume mount from configmap (<a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/#pod-template" rel="nofollow noreferrer">spec template is the same as it used in pods</a>):</p>
<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: mongojob
spec:
  template:
    spec:
      containers:
      - name: mongojob
        image: ubuntu # for testing purposes, you need to use appropriate one
        command: ['bin/bash', '-c', 'echo STARTED ; cat /opt/mongoscript.js ; sleep 120 ; echo FINISHED'] # same for command, that's for demo purposes
        volumeMounts:
        - name: mongoscript
          mountPath: /opt # where to mount the file
      volumes:
      - name: mongoscript
        configMap:
          name: mongoscript-cm # reference to previously created configmap
      restartPolicy: OnFailure # required for jobs
</code></pre>
</li>
<li><p>Checking how it looks inside the pod</p>
<p>Connect to the pod:</p>
<pre><code>$ kubectl exec -it mongojob--1-8w4ml -- /bin/bash
</code></pre>
<p>Check file is presented:</p>
<pre><code># ls /opt
mongoscript.js
</code></pre>
<p>Check its content:</p>
<pre><code># cat /opt/mongoscript.js 
var operations = [];
db.product.find().forEach(function(doc) {
    var documentLink = doc.documentLink; 
    var operation = { updateMany :{ 
&quot;filter&quot; : {&quot;_id&quot; : doc._id},
&quot;update&quot; : {$set {&quot;documentLinkMap.en&quot;:documentLink,&quot;documentLinkMap.de&quot;:&quot;&quot;},
    $unset: {documentLink:&quot;&quot;,&quot;descriptionMap.tr&quot;:&quot;&quot;,&quot;news.tr&quot;:&quot;&quot;,&quot;descriptionInternal.tr&quot;:&quot;&quot;,&quot;salesDescription.tr&quot;:&quot;&quot;,&quot;salesInternal.tr&quot;:&quot;&quot;,&quot;deliveryDescription.tr&quot;:&quot;&quot;,&quot;deliveryInternal.tr&quot;:&quot;&quot;,&quot;productRoadMapDescription.tr&quot;:&quot;&quot;,&quot;productRoadMapInternal.tr&quot;:&quot;&quot;,&quot;technicalsAndIntegration.tr&quot;:&quot;&quot;,&quot;technicalsAndIntegrationInternal.tr&quot;:&quot;&quot;,&quot;versions.$[].descriptionMap.tr&quot;:&quot;&quot;,&quot;versions.$[].releaseNoteMap.tr&quot;:&quot;&quot;,&quot;versions.$[].artifacts.$[].descriptionMap.tr&quot;:&quot;&quot;,&quot;versions.$[].artifacts.$[].artifactNotes.tr&quot;:&quot;&quot;}}}};
    operations.push(operation); 
});
operations.push( {
    ordered: true,      
    writeConcern: { w: &quot;majority&quot;, wtimeout: 5000 } 
});
db.product.bulkWrite(operations);
</code></pre>
</li>
</ol>
