Mongodb-odm: doctrine:mongo:schema:update creates the same index again and again

Created on 9 Jan 2020  路  1Comment  路  Source: doctrine/mongodb-odm

Bug Report

Every time I run doctrine:mongo:schema:update it creates the same index again. On production this takes 6 minutes, resources and probably locks the collection. It should not recreate the index again after it's initial creation.

| Q | A
|------------ | ------
| BC Break | no
| Version | 2.0.3
| MongoDB version | 4.0.14 (hosted on cloud.mongodb.com on M10 server)

Summary

When running the command, I see the following query being executed in cloud.mongodb.com

image (1)

The corresponding document is this:

/**
 * @ODM\Document(repositoryClass="PublicationService\Content\Repository\ContentRepository")
 * @ODM\UniqueIndex(keys={"type"="asc", "identifier"="asc", "revision"="desc"})
 * @ODM\Index(keys={"type"="asc", "code"="asc", "revision"="desc", "identifier"="asc"})
 */
class Content
{
    use ParsableTrait;

    /**
     * combination of "$type|$identifier|$revision" for uniqueness and upserts.
     *
     * @ODM\Id(strategy="NONE")
     */
    private string $id;

    /**
     * @ODM\Field(type="string")
     */
    private string $type;

    /**
     * Arrangement code.
     *
     * Since every stream has it's own unique identifiers, every Content document is now part of a single stream.
     *
     * @ODM\Field(type="string")
     */
    private string $code;

    /**
     * For now, unique id from the thedContentIdentifier.
     * In the future this will be a unique publication service id from Thed.
     *
     * @ODM\Field(type="string")
     */
    private string $identifier;

    /**
     * The revision number of this content.
     * We use the "rev" key, hoping this is an increasing number.
     *
     * @ODM\Field(type="integer")
     */
    private int $revision;

    /**
     * Content (XML string).
     *
     * @ODM\Field(type="string")
     */
    private string $content;

    /**
     * @ODM\Field(type="date")
     */
    private DateTimeInterface $createdAt;

This is what the index looks like when created:

[
    {
        "v" : 2,
        "key" : {
            "_id" : 1
        },
        "name" : "_id_",
        "ns" : "tm-thip-prod.Content"
    },
    {
        "v" : 2,
        "unique" : true,
        "key" : {
            "type" : 1,
            "identifier" : 1,
            "revision" : -1
        },
        "name" : "type_1_identifier_1_revision_-1",
        "sparse" : false,
        "background" : false,
        "ns" : "tm-thip-prod.Content"
    },
    {
        "v" : 2,
        "key" : {
            "type" : 1,
            "code" : 1,
            "revision" : -1,
            "identifier" : 1
        },
        "name" : "type_1_code_1_revision_-1_identifier_1",
        "sparse" : false,
        "background" : false,
        "ns" : "tm-thip-prod.Content"
    }
]

How to reproduce

It happens every time I run doctrine:mongo:schema:update

Expected behavior

I expect the second time that I run doctrine:mongo:schema:update that nothing happends.

Additional info

Not sure if this matters, but saw this in the additional config on cloud mongo

image

But the size seems ok

image

Bug

Most helpful comment

Fixed in #2148.

>All comments

Fixed in #2148.

Was this page helpful?
0 / 5 - 0 ratings