@@ -31,6 +31,32 @@ var RouterConfigCollections = []string{
31
31
32
32
const MetaFileV2 = "meta.pbm"
33
33
34
+ var validIndexOptions = map [string ]bool {
35
+ "2dsphereIndexVersion" : true ,
36
+ "background" : true ,
37
+ "bits" : true ,
38
+ "bucketSize" : true ,
39
+ "coarsestIndexedLevel" : true ,
40
+ "collation" : true ,
41
+ "default_language" : true ,
42
+ "expireAfterSeconds" : true ,
43
+ "finestIndexedLevel" : true ,
44
+ "key" : true ,
45
+ "language_override" : true ,
46
+ "max" : true ,
47
+ "min" : true ,
48
+ "name" : true ,
49
+ "ns" : true ,
50
+ "partialFilterExpression" : true ,
51
+ "sparse" : true ,
52
+ "storageEngine" : true ,
53
+ "textIndexVersion" : true ,
54
+ "unique" : true ,
55
+ "v" : true ,
56
+ "weights" : true ,
57
+ "wildcardProjection" : true ,
58
+ }
59
+
34
60
type ArchiveMetaV2 struct {
35
61
Version string `bson:"version"`
36
62
ServerVersion string `bson:"serverVersion"`
@@ -46,7 +72,7 @@ type NamespaceV2 struct {
46
72
UUID string `bson:"uuid,omitempty"`
47
73
Options bson.D `bson:"options,omitempty"`
48
74
49
- Indexes []* IndexSpec `bson:"indexes"`
75
+ Indexes []IndexSpec `bson:"indexes"`
50
76
51
77
CRC int64 `bson:"crc"`
52
78
Size int64 `bson:"size"`
@@ -63,18 +89,7 @@ func (s *NamespaceV2) IsTimeseries() bool { return s.Type == "timeseries" }
63
89
func (s * NamespaceV2 ) IsSystemCollection () bool { return strings .HasPrefix (s .Name , "system." ) }
64
90
func (s * NamespaceV2 ) IsBucketCollection () bool { return strings .HasPrefix (s .Name , "system.buckets" ) }
65
91
66
- type IndexSpec struct {
67
- Version int32 `bson:"v"`
68
-
69
- Key bson.D `bson:"key"`
70
- Name string `bson:"name"`
71
-
72
- Sparse * bool `bson:"sparse,omitempty"`
73
- Unique * bool `bson:"unique,omitempty"`
74
- Clustered * bool `bson:"clustered,omitempty"`
75
-
76
- ExpireAfterSeconds * int32 `bson:"expireAfterSeconds,omitempty"`
77
- }
92
+ type IndexSpec bson.D
78
93
79
94
type BackupOptions struct {
80
95
Client * mongo.Client
@@ -236,7 +251,7 @@ func (bcp *backupImpl) listDBNamespaces(ctx context.Context, db string) ([]*Name
236
251
return nil , errors .Wrapf (err , "list indexes for %s" , ns .Name )
237
252
}
238
253
} else {
239
- ns .Indexes = []* IndexSpec {}
254
+ ns .Indexes = []IndexSpec {}
240
255
}
241
256
242
257
rv = append (rv , ns )
@@ -245,15 +260,33 @@ func (bcp *backupImpl) listDBNamespaces(ctx context.Context, db string) ([]*Name
245
260
return rv , errors .Wrap (cur .Err (), "cursor" )
246
261
}
247
262
248
- func (bcp * backupImpl ) listIndexes (ctx context.Context , db , coll string ) ([]* IndexSpec , error ) {
263
+ // listIndexes fetches index definitions for the specified namespace.
264
+ // It returns dynamic bson.D index representation which is filtered by allowed index
265
+ // specification keys.
266
+ func (bcp * backupImpl ) listIndexes (ctx context.Context , db , coll string ) ([]IndexSpec , error ) {
249
267
cur , err := bcp .conn .Database (db ).Collection (coll ).Indexes ().List (ctx )
250
268
if err != nil {
251
- return nil , err
269
+ return nil , errors .Wrapf (err , "listIndexes cmd for ns: %s.%s" , db , coll )
270
+ }
271
+
272
+ idxs := []bson.D {}
273
+ err = cur .All (ctx , & idxs )
274
+ if err != nil {
275
+ return nil , errors .Wrapf (err , "decode indexes for ns: %s.%s" , db , coll )
276
+ }
277
+
278
+ var idxSpecs []IndexSpec
279
+ for i := range idxs {
280
+ var idxSpec IndexSpec
281
+ for _ , opt := range idxs [i ] {
282
+ if _ , ok := validIndexOptions [opt .Key ]; ok {
283
+ idxSpec = append (idxSpec , opt )
284
+ }
285
+ }
286
+ idxSpecs = append (idxSpecs , idxSpec )
252
287
}
253
288
254
- var indexes []* IndexSpec
255
- err = cur .All (ctx , & indexes )
256
- return indexes , err
289
+ return idxSpecs , nil
257
290
}
258
291
259
292
func (bcp * backupImpl ) dumpAllCollections (ctx context.Context , nss []* NamespaceV2 ) error {
0 commit comments