I have a slice of objects I want to save to Mongo collection. Let's say
type (
User struct {
AccountId string
Name string
FamilyName string
EmailAddress string
}
)
func persistUsers(ctx context.Context, db *mongo.Collection, users []User) {
}
Some users are already saved, some - aren't. I want to upsert the slice. Hence I have two question:
How can I user
mongo.Collection.BulkWrite()? I can't find obvious explanation how to put slice of objects into it.How do mongo decides what is new, what is old and has to be updated? According to
_id?