Skip to content

Commit eafda64

Browse files
committed
Switch to $documents for index comparison.
1 parent e8b4330 commit eafda64

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

internal/verifier/migration_verifier.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -873,26 +873,15 @@ func (verifier *Verifier) doIndexSpecsMatch(ctx context.Context, srcSpec bson.Ra
873873
}
874874

875875
// Next check to see if the only differences are type differences.
876-
// If we didn’t support pre-v5 servers we could use a $documents aggregation,
877-
// but we can’t do that, so we write to a temporary collection.
878-
coll := verifier.metaClient.Database(verifier.metaDBName).Collection("indexCompare")
879-
insert, err := coll.InsertOne(
880-
ctx,
881-
bson.M{"spec": srcSpec},
882-
)
883-
if err != nil {
884-
return false, errors.Wrap(err, "failed to persist index specification to metadata")
885-
}
886-
887-
defer func() {
888-
_, _ = coll.DeleteOne(ctx, bson.M{"_id": insert.InsertedID})
889-
}()
890-
891-
cursor, err := coll.Aggregate(
876+
// (We can safely use $documents here since this is against the metadata
877+
// cluster, which we can require to be v5+.)
878+
db := verifier.metaClient.Database(verifier.metaDBName)
879+
cursor, err := db.Aggregate(
892880
ctx,
893881
mongo.Pipeline{
894-
// Select our source spec.
895-
{{"$match", bson.D{{"_id", insert.InsertedID}}}},
882+
{{"$documents", []bson.D{
883+
{{"spec", srcSpec}},
884+
}}},
896885

897886
// Add the destination spec.
898887
{{"$addFields", bson.D{

0 commit comments

Comments
 (0)