Skip to content

Commit 6310dd3

Browse files
committed
GODRIVER-692 Set registry on RunCommand result
Change-Id: I8e759ff5e54738684014591654f8e76c37042c52
1 parent 3099975 commit 6310dd3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

mongo/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (db *Database) RunCommand(ctx context.Context, runCommand interface{}, opts
150150
db.client.topology.SessionPool,
151151
)
152152

153-
return &SingleResult{err: replaceTopologyErr(err), rdr: doc}
153+
return &SingleResult{err: replaceTopologyErr(err), rdr: doc, reg: db.registry}
154154
}
155155

156156
// RunCommandCursor runs a command on the database and returns a cursor over the resulting reader. A user can supply

mongo/database_internal_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ func TestDatabase_RunCommand(t *testing.T) {
147147
require.Equal(t, ok.Double(), 1.0)
148148
}
149149

150+
func TestDatabase_RunCommand_DecodeStruct(t *testing.T) {
151+
t.Parallel()
152+
153+
db := createTestDatabase(t, nil)
154+
155+
result := struct {
156+
Ismaster bool `bson:"ismaster"`
157+
Ok float64 `bson:"ok"`
158+
}{}
159+
160+
err := db.RunCommand(context.Background(), bsonx.Doc{{"ismaster", bsonx.Int32(1)}}).Decode(&result)
161+
require.NoError(t, err)
162+
require.Equal(t, result.Ismaster, true)
163+
require.Equal(t, result.Ok, 1.0)
164+
}
165+
150166
func TestDatabase_Drop(t *testing.T) {
151167
t.Parallel()
152168

0 commit comments

Comments
 (0)