@@ -14,6 +14,7 @@ import (
14
14
"fmt"
15
15
"io"
16
16
"reflect"
17
+ "slices"
17
18
"strings"
18
19
"sync/atomic"
19
20
@@ -77,8 +78,6 @@ var selectedNSSupportedCommands = map[string]struct{}{
77
78
"dropIndex" : {},
78
79
"dropIndexes" : {},
79
80
"collMod" : {},
80
- "startIndexBuild" : {},
81
- "abortIndexBuild" : {},
82
81
"commitIndexBuild" : {},
83
82
}
84
83
@@ -258,6 +257,32 @@ func (o *OplogRestore) SetIncludeNS(nss []string) {
258
257
o .includeNS = dbs
259
258
}
260
259
260
+ func isOpAllowed (oe * Record ) bool {
261
+ coll , ok := strings .CutPrefix (oe .Namespace , "config." )
262
+ if ! ok {
263
+ return true // OK: not a "config" database. allow any ops
264
+ }
265
+
266
+ if slices .Contains (dumprestore .ConfigCollectionsToKeep , coll ) {
267
+ return true // OK: create/update/delete a doc
268
+ }
269
+
270
+ if coll != "$cmd" || len (oe .Object ) == 0 {
271
+ return false // other collection is not allowed
272
+ }
273
+
274
+ op := oe .Object [0 ].Key
275
+ if op == "applyOps" {
276
+ return true // internal ops of applyOps are checked one by one later
277
+ }
278
+ if _ , ok := selectedNSSupportedCommands [op ]; ok {
279
+ s , _ := oe .Object [0 ].Value .(string )
280
+ return slices .Contains (dumprestore .ConfigCollectionsToKeep , s )
281
+ }
282
+
283
+ return false
284
+ }
285
+
261
286
func (o * OplogRestore ) isOpSelected (oe * Record ) bool {
262
287
if o .includeNS == nil || o .includeNS ["" ] != nil {
263
288
return true
@@ -273,11 +298,13 @@ func (o *OplogRestore) isOpSelected(oe *Record) bool {
273
298
return false
274
299
}
275
300
276
- for _ , el := range oe .Object {
277
- if _ , ok := selectedNSSupportedCommands [el .Key ]; ok {
278
- s , _ := el .Value .(string )
279
- return colls [s ]
280
- }
301
+ cmd := oe .Object [0 ].Key
302
+ if cmd == "applyOps" {
303
+ return true // internal ops of applyOps are checked one by one later
304
+ }
305
+ if _ , ok := selectedNSSupportedCommands [cmd ]; ok {
306
+ s , _ := oe .Object [0 ].Value .(string )
307
+ return colls [s ]
281
308
}
282
309
283
310
return false
@@ -302,13 +329,7 @@ func (o *OplogRestore) handleOp(oe db.Oplog) error {
302
329
return nil
303
330
}
304
331
305
- if db , coll , _ := strings .Cut (oe .Namespace , "." ); db == "config" {
306
- if ! sliceContains (dumprestore .ConfigCollectionsToKeep , coll ) {
307
- return nil
308
- }
309
- }
310
-
311
- if ! o .isOpSelected (& oe ) {
332
+ if ! isOpAllowed (& oe ) || ! o .isOpSelected (& oe ) {
312
333
return nil
313
334
}
314
335
@@ -631,10 +652,8 @@ func (o *OplogRestore) handleNonTxnOp(op db.Oplog) error {
631
652
return nil
632
653
}
633
654
634
- if db , coll , _ := strings .Cut (op .Namespace , "." ); db == "config" {
635
- if ! sliceContains (dumprestore .ConfigCollectionsToKeep , coll ) {
636
- return nil
637
- }
655
+ if ! isOpAllowed (& op ) || ! o .isOpSelected (& op ) {
656
+ return nil
638
657
}
639
658
640
659
op , err := o .filterUUIDs (op )
0 commit comments