mongoimport E11000 duplicate key due to index
<p>I have a collection with the following fields:</p>

<pre><code>name
type
color
</code></pre>

<p>I also have a unique index <code>name_1_type_1</code>.</p>

<p>Assuming a data set:</p>



<pre class="lang-js prettyprint-override"><code>[{
  name: "name1",
  type: "type1",
  color: "blue"
}, {
  name: "name2",
  type: "type1",
  color: "green"
}]
</code></pre>

<p>Using <code>mongoimport</code> I create the initial data set.</p>

<p>Now, I need to update the collection in order to achieve the following 3 goals:</p>

<ol>
<li>insert new documents (e.g. <code>name1</code>-<code>type2</code> in snippet below)</li>
<li>update <code>color</code> in existing documents (e.g. <code>blue</code>-><code>red</code> in <code>name1</code> below)</li>
<li><p>append a new optional field <code>shape</code> in some documents</p>

<pre class="lang-js prettyprint-override"><code>[
    {
        name: "name1",
        type: "type1",
        color: "red",
        shape: "circle"
    }, 
    {
        name: "name1",
        type: "type2",
        color: "green",
        shape: "rectangle"
    }
]
</code></pre></li>
</ol>

<p>However, when executing <code>mongoimport --upsert</code> on the above json file, I get:</p>

<blockquote>
  <p>error inserting documents: E11000 duplicate key error collection:
  test.col1 index: name_1_type_1 dup key</p>
</blockquote>

<p>Maybe I am using <code>mongoimport</code> in a wrong way.</p>

<p>How can I achieve the 3 above mentioned upsert goals using mongoimport? </p>