mongodb-odm icon indicating copy to clipboard operation
mongodb-odm copied to clipboard

Embedded document index with partialFilterExpression is wrong

Open Steveb-p opened this issue 4 years ago • 2 comments

Bug Report

Q A
BC Break no
Version 2.1.2

Summary

Embedded documents when creating indexes receive them with wrong partialFilterExpression, as if they were not embedded.

Current behavior

For a document class:

/**
 * @ODM\EmbeddedDocument(indexes={
 *      @ODM\Index(
 *          background=true,
 *          name="statistic_aggregate_transaction_state_idx",
 *          keys={
 *              "last_changed"="asc",
 *              "transaction_state"="asc",
 *          },
 *          partialFilterExpression={
 *              "transaction_state"=StatisticAggregateState::TRANSACTION_STATE_CHANGESET_NEW,
 *          },
 *      ),
 * })
 */
class StatisticAggregateState
{
    private const TRANSACTION_STATE_CHANGESET_APPLIED = 'applied';
    public const TRANSACTION_STATE_CHANGESET_NEW = 'new';
    ...
}

...creates an index with following specification:

db.collection.createIndex(
    {
        "statistic_aggregate_states.transaction_state": 1,
        "statistic_aggregate_states.last_changed": 1
    },
    {
        name: "statistic_aggregate_states_statistic_aggregate_transaction_state_idx",
        background: true,
        partialFilterExpression: {
            transaction_state: "new"
        }
    }
)

Expected behavior

Created index should actually be:

db.collection.createIndex(
    {
        "statistic_aggregate_states.transaction_state": 1,
        "statistic_aggregate_states.last_changed": 1
    },
    {
        name: "statistic_aggregate_states_statistic_aggregate_transaction_state_idx",
        background: true,
        partialFilterExpression: {
            "statistic_aggregate_states.transaction_state": "new"
        }
    }
)

Steveb-p avatar Jul 25 '20 16:07 Steveb-p

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 25 '20 23:08 stale[bot]

Given partial indexes were introduced in 1.1 (#1303) this needs to be fixed in 1.3.x branch and then merged up. Gonna schedule it so the report won't fall through the cracks

malarzm avatar Sep 01 '20 21:09 malarzm