Skip to content

Conversation

@inelpandzic
Copy link
Collaborator

@inelpandzic inelpandzic commented Nov 18, 2025

PCSM-200 Powered by Pull Request Badge

Problem

In replication PCSM is collecting all CRUD events in memory and then sending them in bulk to the target cluster. For a sharded collection that has a non-default collation for MongoDB versions below 8, when performing a bulk write operation it fails with:

bulk write exception: write errors: [Failed to target upsert by query :: caused by :: Cannot target single shard due to collation of key _id for namespace test_db1.test_coll]"

In order to solve this, bulk write operation for this case has to hold collation specified to locale:simple, something like this

db.test_coll.bulkWrite([
  {
    replaceOne: {
      filter: { _id: 444},
      replacement: { _id: 444, value: 1 },
      upsert: true,
      collation: { locale: "simple"}   <==============
    }
  }
])

Solution

Update the catalog so that it holds a sharded field for sharded collection so PCSM knows from the catalog that it is a sharded collection. This will most likely be used in the future when working on improving sharding support.

Besides this field now, based on the target version, collectionBulkWrite and cliendBulkWrite structs will hold a useSimpleCollation flag.

With these two new fields, now when we read some CRUD event, we can determine to add a collation locale:simple option to the bulk write command.

@inelpandzic inelpandzic merged commit f4824c9 into main Nov 19, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants