Skip to content

Commit

Permalink
GODRIVER-2323 Support int64 for 'n' field in insert, update, and dele…
Browse files Browse the repository at this point in the history
…te ops. (#905)
  • Loading branch information
matthewdale committed Apr 11, 2022
1 parent b5c26f5 commit 7ff10a8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions mongo/bulk_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (bw *bulkWrite) runBatch(ctx context.Context, batch bulkWriteBatch) (BulkWr
batchErr.Labels = writeErr.Labels
batchErr.WriteConcernError = convertDriverWriteConcernError(writeErr.WriteConcernError)
}
batchRes.InsertedCount = int64(res.N)
batchRes.InsertedCount = res.N
case *DeleteOneModel, *DeleteManyModel:
res, err := bw.runDelete(ctx, batch)
if err != nil {
Expand All @@ -126,7 +126,7 @@ func (bw *bulkWrite) runBatch(ctx context.Context, batch bulkWriteBatch) (BulkWr
batchErr.Labels = writeErr.Labels
batchErr.WriteConcernError = convertDriverWriteConcernError(writeErr.WriteConcernError)
}
batchRes.DeletedCount = int64(res.N)
batchRes.DeletedCount = res.N
case *ReplaceOneModel, *UpdateOneModel, *UpdateManyModel:
res, err := bw.runUpdate(ctx, batch)
if err != nil {
Expand All @@ -138,8 +138,8 @@ func (bw *bulkWrite) runBatch(ctx context.Context, batch bulkWriteBatch) (BulkWr
batchErr.Labels = writeErr.Labels
batchErr.WriteConcernError = convertDriverWriteConcernError(writeErr.WriteConcernError)
}
batchRes.MatchedCount = int64(res.N)
batchRes.ModifiedCount = int64(res.NModified)
batchRes.MatchedCount = res.N
batchRes.ModifiedCount = res.NModified
batchRes.UpsertedCount = int64(len(res.Upserted))
for _, upsert := range res.Upserted {
batchRes.UpsertedIDs[int64(batch.indexes[upsert.Index])] = upsert.ID
Expand Down
6 changes: 3 additions & 3 deletions mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func (coll *Collection) delete(ctx context.Context, filter interface{}, deleteOn
if rr&expectedRr == 0 {
return nil, err
}
return &DeleteResult{DeletedCount: int64(op.Result().N)}, err
return &DeleteResult{DeletedCount: op.Result().N}, err
}

// DeleteOne executes a delete command to delete at most one document from the collection.
Expand Down Expand Up @@ -582,8 +582,8 @@ func (coll *Collection) updateOrReplace(ctx context.Context, filter bsoncore.Doc

opRes := op.Result()
res := &UpdateResult{
MatchedCount: int64(opRes.N),
ModifiedCount: int64(opRes.NModified),
MatchedCount: opRes.N,
ModifiedCount: opRes.NModified,
UpsertedCount: int64(len(opRes.Upserted)),
}
if len(opRes.Upserted) > 0 {
Expand Down
6 changes: 3 additions & 3 deletions x/mongo/driver/operation/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Delete struct {
// DeleteResult represents a delete result returned by the server.
type DeleteResult struct {
// Number of documents successfully deleted.
N int32
N int64
}

func buildDeleteResult(response bsoncore.Document) (DeleteResult, error) {
Expand All @@ -55,9 +55,9 @@ func buildDeleteResult(response bsoncore.Document) (DeleteResult, error) {
switch element.Key() {
case "n":
var ok bool
dr.N, ok = element.Value().AsInt32OK()
dr.N, ok = element.Value().AsInt64OK()
if !ok {
return dr, fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type)
return dr, fmt.Errorf("response field 'n' is type int32 or int64, but received BSON type %s", element.Value().Type)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions x/mongo/driver/operation/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Insert struct {
// InsertResult represents an insert result returned by the server.
type InsertResult struct {
// Number of documents successfully inserted.
N int32
N int64
}

func buildInsertResult(response bsoncore.Document) (InsertResult, error) {
Expand All @@ -54,9 +54,9 @@ func buildInsertResult(response bsoncore.Document) (InsertResult, error) {
switch element.Key() {
case "n":
var ok bool
ir.N, ok = element.Value().AsInt32OK()
ir.N, ok = element.Value().AsInt64OK()
if !ok {
return ir, fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type)
return ir, fmt.Errorf("response field 'n' is type int32 or int64, but received BSON type %s", element.Value().Type)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions x/mongo/driver/operation/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ type Upsert struct {
// UpdateResult contains information for the result of an Update operation.
type UpdateResult struct {
// Number of documents matched.
N int32
N int64
// Number of documents modified.
NModified int32
NModified int64
// Information about upserted documents.
Upserted []Upsert
}
Expand All @@ -68,15 +68,15 @@ func buildUpdateResult(response bsoncore.Document) (UpdateResult, error) {
switch element.Key() {
case "nModified":
var ok bool
ur.NModified, ok = element.Value().Int32OK()
ur.NModified, ok = element.Value().AsInt64OK()
if !ok {
return ur, fmt.Errorf("response field 'nModified' is type int32, but received BSON type %s", element.Value().Type)
return ur, fmt.Errorf("response field 'nModified' is type int32 or int64, but received BSON type %s", element.Value().Type)
}
case "n":
var ok bool
ur.N, ok = element.Value().Int32OK()
ur.N, ok = element.Value().AsInt64OK()
if !ok {
return ur, fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type)
return ur, fmt.Errorf("response field 'n' is type int32 or int64, but received BSON type %s", element.Value().Type)
}
case "upserted":
arr, ok := element.Value().ArrayOK()
Expand Down

0 comments on commit 7ff10a8

Please sign in to comment.