Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-30638

Use partialFilterExpression on parentId when creating the unique index to avoid duplicates

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 10.10
    • Fix Version/s: 10.10-HF58, 2021.15
    • Component/s: Core MongoDB
    • Release Notes Summary:
      Enabling unique child constraint doesn't prevent version creation anymore
    • Backlog priority:
      750
    • Upgrade notes:
      Hide

      For LTS 2019

      Setup having the childNameUniqueConstraintEnabled enabled on MongoDB will need to drop the ecm:parentId_1_ecm:name_1 before starting Nuxeo with the fix installed.
      You should run the command below in a MongoDB in a MongoDB Shell (assuming you're connected to the nuxeo database and your repository is default):

      db.default.dropIndex("ecm:parentId_1_ecm:name_1");
      

      For LTS 2021

      You must run the command below in a MongoDB Shell (assuming you're connected to the nuxeo database and your repository is default):

      db.default.dropIndex("ecm:parentId_1_ecm:name_1");
      

      As a workaround, you can configure the nuxeo.db.indexes.create property to false in nuxeo.conf.

      Show
      For LTS 2019 Setup having the childNameUniqueConstraintEnabled enabled on MongoDB will need to drop the ecm:parentId_1_ecm:name_1 before starting Nuxeo with the fix installed. You should run the command below in a MongoDB in a MongoDB Shell (assuming you're connected to the nuxeo  database and your repository is default ): db. default .dropIndex( "ecm:parentId_1_ecm:name_1" ); For LTS 2021 You must run the command below in a MongoDB Shell (assuming you're connected to the nuxeo  database and your repository is default ): db. default .dropIndex( "ecm:parentId_1_ecm:name_1" ); As a workaround, you can configure the nuxeo.db.indexes.create property to false in nuxeo.conf .
    • Sprint:
      nxplatform #52, nxplatform #53
    • Story Points:
      0

      Description

      For MongoDB repository, Nuxeo adds a unique index on "ecm:name ; ecm:parentId" to prevent from creating several documents with the same name in a given container with

              IndexOptions parentNameIndexOptions = new IndexOptions();
              parentNameIndexOptions.unique(true);
              coll.createIndex(Indexes.ascending(KEY_PARENT_ID, KEY_NAME), parentNameIndexOptions);
      

      However this index prevents from creating versions (there is an error when creating the second version as it has the same name and the same "null" parent).

      It is required to add a partialFilterExpression attribute on the index creation like

      db.default.createIndex( { "ecm:parentId": 1, "ecm:name": 1 }, { unique: true, partialFilterExpression: {'ecm:parentId':{$gt:""}} } )
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: