I get this error while trying to insert data from a JSON file. Only one item is added to the database.
11000 E11000 duplicate key error index: awdb.mycollection.$_id_ dup
> key: { : ObjectId('53954d897aadbe032a33cd68') }
> > db.mycollection.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "awdb.mycollection"
},
{
"v" : 1,
"unique" : true,
"key" : {
"UDID" : 1
},
"name" : "UDID_1",
"ns" : "awdb.mycollection",
"sparse" : true
}
]
>
The following is the JSON input file I am using.
{"UDID":"1234","FriendlyName":"Ben Android","sn":"abc123","ManDate":"12/12/8234"}
{"UDID":"1235","FriendlyName":"Android","sn":"abc23","ManDate":"12/12/1254"}
{"UDID":"1236","FriendlyName":"Ben droid","sn":"abc12","ManDate":"12/12/1734"}
Here is the code im using to insert the JSON
while ((sCurrentLine = br.readLine()) != null) {
d=g.fromJson(sCurrentLine, Device.class);
m.create(d);
}
And here is my create function
public boolean create(Device d) {
document.put("UDID",d.UDID);
document.put("name", d.FriendlyName);
document.put("Serial", d.sn);
document.put("Manf", d.ManDate);
collection.insert(document);
return true;
}
And my Device class
public class Device {
public String UDID;
public String FriendlyName;
public String sn;
public String ManDate;
}