Skip to content

Commit 7ff10a8

Browse files
committed
GODRIVER-2323 Support int64 for 'n' field in insert, update, and delete ops. (#905)
1 parent b5c26f5 commit 7ff10a8

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

mongo/bulk_write.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (bw *bulkWrite) runBatch(ctx context.Context, batch bulkWriteBatch) (BulkWr
114114
batchErr.Labels = writeErr.Labels
115115
batchErr.WriteConcernError = convertDriverWriteConcernError(writeErr.WriteConcernError)
116116
}
117-
batchRes.InsertedCount = int64(res.N)
117+
batchRes.InsertedCount = res.N
118118
case *DeleteOneModel, *DeleteManyModel:
119119
res, err := bw.runDelete(ctx, batch)
120120
if err != nil {
@@ -126,7 +126,7 @@ func (bw *bulkWrite) runBatch(ctx context.Context, batch bulkWriteBatch) (BulkWr
126126
batchErr.Labels = writeErr.Labels
127127
batchErr.WriteConcernError = convertDriverWriteConcernError(writeErr.WriteConcernError)
128128
}
129-
batchRes.DeletedCount = int64(res.N)
129+
batchRes.DeletedCount = res.N
130130
case *ReplaceOneModel, *UpdateOneModel, *UpdateManyModel:
131131
res, err := bw.runUpdate(ctx, batch)
132132
if err != nil {
@@ -138,8 +138,8 @@ func (bw *bulkWrite) runBatch(ctx context.Context, batch bulkWriteBatch) (BulkWr
138138
batchErr.Labels = writeErr.Labels
139139
batchErr.WriteConcernError = convertDriverWriteConcernError(writeErr.WriteConcernError)
140140
}
141-
batchRes.MatchedCount = int64(res.N)
142-
batchRes.ModifiedCount = int64(res.NModified)
141+
batchRes.MatchedCount = res.N
142+
batchRes.ModifiedCount = res.NModified
143143
batchRes.UpsertedCount = int64(len(res.Upserted))
144144
for _, upsert := range res.Upserted {
145145
batchRes.UpsertedIDs[int64(batch.indexes[upsert.Index])] = upsert.ID

mongo/collection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func (coll *Collection) delete(ctx context.Context, filter interface{}, deleteOn
473473
if rr&expectedRr == 0 {
474474
return nil, err
475475
}
476-
return &DeleteResult{DeletedCount: int64(op.Result().N)}, err
476+
return &DeleteResult{DeletedCount: op.Result().N}, err
477477
}
478478

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

583583
opRes := op.Result()
584584
res := &UpdateResult{
585-
MatchedCount: int64(opRes.N),
586-
ModifiedCount: int64(opRes.NModified),
585+
MatchedCount: opRes.N,
586+
ModifiedCount: opRes.NModified,
587587
UpsertedCount: int64(len(opRes.Upserted)),
588588
}
589589
if len(opRes.Upserted) > 0 {

x/mongo/driver/operation/delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Delete struct {
4242
// DeleteResult represents a delete result returned by the server.
4343
type DeleteResult struct {
4444
// Number of documents successfully deleted.
45-
N int32
45+
N int64
4646
}
4747

4848
func buildDeleteResult(response bsoncore.Document) (DeleteResult, error) {
@@ -55,9 +55,9 @@ func buildDeleteResult(response bsoncore.Document) (DeleteResult, error) {
5555
switch element.Key() {
5656
case "n":
5757
var ok bool
58-
dr.N, ok = element.Value().AsInt32OK()
58+
dr.N, ok = element.Value().AsInt64OK()
5959
if !ok {
60-
return dr, fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type)
60+
return dr, fmt.Errorf("response field 'n' is type int32 or int64, but received BSON type %s", element.Value().Type)
6161
}
6262
}
6363
}

x/mongo/driver/operation/insert.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Insert struct {
4141
// InsertResult represents an insert result returned by the server.
4242
type InsertResult struct {
4343
// Number of documents successfully inserted.
44-
N int32
44+
N int64
4545
}
4646

4747
func buildInsertResult(response bsoncore.Document) (InsertResult, error) {
@@ -54,9 +54,9 @@ func buildInsertResult(response bsoncore.Document) (InsertResult, error) {
5454
switch element.Key() {
5555
case "n":
5656
var ok bool
57-
ir.N, ok = element.Value().AsInt32OK()
57+
ir.N, ok = element.Value().AsInt64OK()
5858
if !ok {
59-
return ir, fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type)
59+
return ir, fmt.Errorf("response field 'n' is type int32 or int64, but received BSON type %s", element.Value().Type)
6060
}
6161
}
6262
}

x/mongo/driver/operation/update.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ type Upsert struct {
5151
// UpdateResult contains information for the result of an Update operation.
5252
type UpdateResult struct {
5353
// Number of documents matched.
54-
N int32
54+
N int64
5555
// Number of documents modified.
56-
NModified int32
56+
NModified int64
5757
// Information about upserted documents.
5858
Upserted []Upsert
5959
}
@@ -68,15 +68,15 @@ func buildUpdateResult(response bsoncore.Document) (UpdateResult, error) {
6868
switch element.Key() {
6969
case "nModified":
7070
var ok bool
71-
ur.NModified, ok = element.Value().Int32OK()
71+
ur.NModified, ok = element.Value().AsInt64OK()
7272
if !ok {
73-
return ur, fmt.Errorf("response field 'nModified' is type int32, but received BSON type %s", element.Value().Type)
73+
return ur, fmt.Errorf("response field 'nModified' is type int32 or int64, but received BSON type %s", element.Value().Type)
7474
}
7575
case "n":
7676
var ok bool
77-
ur.N, ok = element.Value().Int32OK()
77+
ur.N, ok = element.Value().AsInt64OK()
7878
if !ok {
79-
return ur, fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type)
79+
return ur, fmt.Errorf("response field 'n' is type int32 or int64, but received BSON type %s", element.Value().Type)
8080
}
8181
case "upserted":
8282
arr, ok := element.Value().ArrayOK()

0 commit comments

Comments
 (0)