@@ -158,13 +158,43 @@ type ResponseInfo struct {
158
158
}
159
159
160
160
func redactStartedInformationCmd (info startedInformation ) bson.Raw {
161
+ intLen := func (n int ) int {
162
+ if n == 0 {
163
+ return 1 // Special case: 0 has one digit
164
+ }
165
+ count := 0
166
+ for n > 0 {
167
+ n /= 10
168
+ count ++
169
+ }
170
+ return count
171
+ }
172
+
161
173
var cmdCopy bson.Raw
162
174
163
175
// Make a copy of the command. Redact if the command is security
164
176
// sensitive and cannot be monitored. If there was a type 1 payload for
165
177
// the current batch, convert it to a BSON array
166
178
if ! info .redacted {
167
- cmdCopy = make ([]byte , 0 , len (info .cmd ))
179
+ cmdLen := len (info .cmd )
180
+ for _ , seq := range info .documentSequences {
181
+ cmdLen += 7 // 2 (header) + 4 (array length) + 1 (array end)
182
+ cmdLen += len (seq .identifier )
183
+ data := seq .data
184
+ i := 0
185
+ for {
186
+ doc , rest , ok := bsoncore .ReadDocument (data )
187
+ if ! ok {
188
+ break
189
+ }
190
+ data = rest
191
+ cmdLen += len (doc )
192
+ cmdLen += intLen (i )
193
+ i ++
194
+ }
195
+ }
196
+
197
+ cmdCopy = make ([]byte , 0 , cmdLen )
168
198
cmdCopy = append (cmdCopy , info .cmd ... )
169
199
170
200
if len (info .documentSequences ) > 0 {
@@ -1808,7 +1838,6 @@ func (op Operation) createReadPref(desc description.SelectedServer, isOpQuery bo
1808
1838
// TODO if supplied readPreference was "overwritten" with primary in description.selectForReplicaSet.
1809
1839
if desc .Server .Kind == description .ServerKindStandalone || (isOpQuery &&
1810
1840
desc .Server .Kind != description .ServerKindMongos ) ||
1811
-
1812
1841
op .Type == Write || (op .IsOutputAggregate && desc .Server .WireVersion .Max < 13 ) {
1813
1842
// Don't send read preference for:
1814
1843
// 1. all standalones
0 commit comments