Im trying to bulk write using the new mongo drivers https://godoc.org/go.mongodb.org/mongo-driver/mongo.
models := []mongo.WriteModel{}
for i := 0; i <= 3; i++{
models = append(models, mongo.NewInsertOneModel().SetDocument(bson.M{
"language":"es",
"devideType":i,
}))
}
_, err := client.Database("mydb").Collection("mycoll").BulkWrite(context.TODO(), models)
if err != nil{
log.Println(err)
}
// len(models) - 1, 2, 3.
when i see how many items are in my slice, i get 1, 2, 3. So all together 6 items. Which shouldve been just 3.
This inserts 6 items instead of 3, and im not sure how to fix it.
InsertMany
method wouldve been possible, but its mandatory to work with BulkWrite