Я пытаюсь обновить документ MongoDB с go.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
c, _ := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
col := c.Database("epgrec").Collection("rec")
filter := bson.M{"_id": r.Mid}
update := bson.M{
"$set": bson.M{
"rid": r.Rid,
"channel": r.Channel,
"sid": r.Sid,
"pid": r.Pid,
"start": r.Start,
"duration": r.Duration,
"title": r.Title,
"status": r.Status,
"cmdarray": r.CmdArray,
"workingdir": r.WorkingDir,
},
}
res, err := col.UpdateOne(ctx, filter, update)
У меня ошибка ниже.
multiple write errors: [{write errors: [{E11000 duplicate key error collection: epgrec.rec index: _id_ dup key: { : ObjectId('5d163936ead22a4f85f1e607') }}]}, {<nil>}]
exit status 1
с использованием драйвера MongoDB v1.0.3 (от go.mongodb.org/mongo-driver/mongo)
Как мне избежать этой ошибки? Пожалуйста, помогите.