I am doing an UpdateOne with upsert true.
What do I set the ID field as when I am doing an upsert?
log.Println(“Saving Partner…”)
q := bson.D{{Key: “_id”, Value: i.ID}}
update := bson.D{{
Key: “$set”,
Value: i,
}}
m, err := s.C.UpdateOne(c, q, update, &options.UpdateOptions{
Upsert: newTrue(),
})
return m, err
an ID field, _id
, means you already have a document, so the operation will not be an upsert (update-or-insert) but instead be just an update.
upsert is for queries without an ID such that if there is no document to “match” your criteria, then a new one with the content you send to the server will be inserted with a new server-generated ID.