Skip to content

Commit

Permalink
fixed: use oid in upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
primalmotion committed Oct 29, 2019
1 parent 6250df8 commit 0be22f2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions manipmongo/manipulator.go
Expand Up @@ -339,7 +339,8 @@ func (m *mongoManipulator) Create(mctx manipulate.Context, object elemental.Iden
c, close := m.makeSession(object.Identity(), mctx.ReadConsistency(), mctx.WriteConsistency())
defer close()

object.SetIdentifier(bson.NewObjectId().Hex())
oid := bson.NewObjectId()
object.SetIdentifier(oid.Hex())

sp := tracing.StartTrace(mctx, fmt.Sprintf("manipmongo.create.object.%s", object.Identity().Name))
sp.LogFields(log.String("object_id", object.Identifier()))
Expand Down Expand Up @@ -372,7 +373,6 @@ func (m *mongoManipulator) Create(mctx manipulate.Context, object elemental.Iden
var err error
if operations, upsert := mctx.(opaquer).Opaque()[opaqueKeyUpsert]; upsert {

id := object.Identifier()
object.SetIdentifier("")

ops, ok := operations.(bson.M)
Expand All @@ -382,7 +382,7 @@ func (m *mongoManipulator) Create(mctx manipulate.Context, object elemental.Iden

baseOps := bson.M{
"$set": object,
"$setOnInsert": bson.M{"_id": id},
"$setOnInsert": bson.M{"_id": oid},
}

if len(ops) > 0 {
Expand Down Expand Up @@ -421,7 +421,7 @@ func (m *mongoManipulator) Create(mctx manipulate.Context, object elemental.Iden
defaultRetryFunc: m.defaultRetryFunc,
},
)
object.SetIdentifier(id)
object.SetIdentifier(oid.Hex())
} else {
_, err = RunQuery(
mctx,
Expand Down

0 comments on commit 0be22f2

Please sign in to comment.