TEST_F(InternalUnpackBucketSplitMatchOnMetaAndRename, SplitsAndRenamesWhenSeveralFieldReferences) {
    auto unpack = DocumentSourceInternalUnpackBucket::createFromBsonInternal(
        fromjson("{$_internalUnpackBucket: { exclude: [], timeField: 'foo', metaField: 'myMeta', "
                 "bucketMaxSpanSeconds: 3600}}")
            .firstElement(),
        getExpCtx());
    auto matchToSplit = DocumentSourceMatch::create(
        fromjson("{$and: [{myMeta: {$type: [3]}}, {'myMeta.a': {$gte: "
                 "0}}, {'myMeta.b': {$type: [4]}}, {a: {$in: ['$b', '$c']}}]}"),
        getExpCtx());

    auto [metaOnlyMatch, remainingMatch] =
        dynamic_cast<DocumentSourceInternalUnpackBucket*>(unpack.get())
            ->splitMatchOnMetaAndRename(matchToSplit.get());

    // Can split and rename when the $match includes several field references.
    ASSERT_TRUE(metaOnlyMatch);
    ASSERT_BSONOBJ_EQ(fromjson("{$and: [{meta: {$type: [3]}}, {'meta.a': {$gte: 0}}, "
                               "{'meta.b': {$type: [4]}}]}"),
                      metaOnlyMatch->getQuery());
    ASSERT_TRUE(remainingMatch);
    ASSERT_BSONOBJ_EQ(fromjson("{a: {$in: ['$b', '$c']}}"), remainingMatch->getQuery());
}
TEST_F(InternalUnpackBucketSplitMatchOnMetaAndRename, SplitsAndRenamesWhenSeveralFieldReferences) {
    auto unpack = DocumentSourceInternalUnpackBucket::createFromBsonInternal(
        fromjson("{$_internalUnpackBucket: { exclude: [], timeField: 'foo', metaField: 'myMeta', "
                 "bucketMaxSpanSeconds: 3600}}")
            .firstElement(),
        getExpCtx());
    auto matchToSplit = DocumentSourceMatch::create(
        fromjson("{$and: [{myMeta: {$type: [3]}}, {'myMeta.a': {$gte: "
                 "0}}, {'myMeta.b': {$type: [4]}}, {a: {$in: ['$b', '$c']}}]}"),
        getExpCtx());

    auto [metaOnlyMatch, remainingMatch] =
        dynamic_cast<DocumentSourceInternalUnpackBucket*>(unpack.get())
            ->splitMatchOnMetaAndRename(matchToSplit.get());

     
    ASSERT_TRUE(metaOnlyMatch);
    ASSERT_BSONOBJ_EQ(fromjson("{$and: [{meta: {$type: [3]}}, {'meta.a': {$gte: 0}}, "
                               "{'meta.b': {$type: [4]}}]}"),
                      metaOnlyMatch->getQuery());
    ASSERT_TRUE(remainingMatch);
    ASSERT_BSONOBJ_EQ(fromjson("{a: {$in: ['$b', '$c']}}"), remainingMatch->getQuery());
}