I have a collection with the following fields:
name
type
color
I also have a unique index name_1_type_1
.
Assuming a data set:
[{
name: "name1",
type: "type1",
color: "blue"
}, {
name: "name2",
type: "type1",
color: "green"
}]
Using mongoimport
I create the initial data set.
Now, I need to update the collection in order to achieve the following 3 goals:
- insert new documents (e.g.
name1
-type2
in snippet below) - update
color
in existing documents (e.g.blue
->red
inname1
below) append a new optional field
shape
in some documents[ { name: "name1", type: "type1", color: "red", shape: "circle" }, { name: "name1", type: "type2", color: "green", shape: "rectangle" } ]
However, when executing mongoimport --upsert
on the above json file, I get:
error inserting documents: E11000 duplicate key error collection: test.col1 index: name_1_type_1 dup key
Maybe I am using mongoimport
in a wrong way.
How can I achieve the 3 above mentioned upsert goals using mongoimport?