@@ -23,6 +23,7 @@ import (
2323 "github.com/10gen/migration-verifier/internal/util"
2424 "github.com/10gen/migration-verifier/internal/uuidutil"
2525 "github.com/10gen/migration-verifier/mbson"
26+ "github.com/10gen/migration-verifier/mslices"
2627 "github.com/10gen/migration-verifier/option"
2728 "github.com/olekukonko/tablewriter"
2829 "github.com/pkg/errors"
@@ -887,14 +888,44 @@ func (verifier *Verifier) doIndexSpecsMatch(ctx context.Context, srcSpec bson.Ra
887888 coll .DeleteOne (ctx , bson.M {"_id" : insert .InsertedID })
888889 }()
889890
890- count , err := coll .CountDocuments (
891+ cursor , err := coll .Aggregate (
891892 ctx ,
892- bson.D {
893- {"_id" , insert .InsertedID },
894- {"spec" , dstSpec },
893+ mongo.Pipeline {
894+ // Select our source spec.
895+ {{"$match" , bson.D {{"_id" , insert .InsertedID }}}},
896+
897+ // Add the destination spec.
898+ {{"$addFields" , bson.D {
899+ {"dstSpec" , dstSpec },
900+ }}},
901+
902+ // Remove the “ns” field from both. (NB: 4.4+ don’t create these,
903+ // though in-place upgrades may cause them still to exist.)
904+ {{"$addFields" , bson.D {
905+ {"spec.ns" , "$$REMOVE" },
906+ {"dstSpec.ns" , "$$REMOVE" },
907+ }}},
908+
909+ // Now check to be sure that those specs match.
910+ {{"$match" , bson.D {
911+ {"$expr" , bson.D {
912+ {"$eq" , mslices .Of ("$spec" , "$dstSpec" )},
913+ }},
914+ }}},
895915 },
896916 )
897917
918+ if err != nil {
919+ return false , errors .Wrap (err , "failed to check index specification match in metadata" )
920+ }
921+ var docs []bson.Raw
922+ err = cursor .All (ctx , & docs )
923+ if err != nil {
924+ return false , errors .Wrap (err , "failed to parse index specification match’s result" )
925+ }
926+
927+ count := len (docs )
928+
898929 switch count {
899930 case 0 :
900931 return false , nil
@@ -1212,7 +1243,6 @@ func (verifier *Verifier) verifyMetadataAndPartitionCollection(ctx context.Conte
12121243 partitions , shardKeys , docsCount , bytesCount , err := verifier .partitionAndInspectNamespace (ctx , srcNs )
12131244 if err != nil {
12141245 task .Status = verificationTaskFailed
1215-
12161246 verifier .logger .Error ().Msgf ("[Worker %d] Error partitioning collection: %+v" , workerNum , err )
12171247 return
12181248 }
0 commit comments