Repository: quarkusio/quarkus
Issue: Panache MongoDB doesn't support collation in count

### Describe the bug

Panache MongoDB doesn't support `collation` for `count`.
Taking a look in the `io.quarkus.mongodb.panache.common.runtime.CommonPanacheQueryImpl` and `io.quarkus.mongodb.panache.common.reactive.runtime.CommonReactivePanacheQueryImpl` we can see the method `count` doesn't support `collation`.

Native queries and panache queries already support this, we can confirm in this [PR](https://github.com/loicmathieu/quarkus/commit/5c0a0a2112cc2d33ecc300618f0694846d0f0f1c#diff-610ce4a20cb8ce7c6942db761ecaebe7a4b6fc761e4b4f0b15b7406ec7db305f) from @loicmathieu already merged.

I implemented the fix, basically I changed a small piece in `CommonReactivePanacheQueryImpl` and `CommonPanacheQueryImpl`:

```
public Uni<Long> count() {
        if (count == null) {
            CountOptions countOptions = new CountOptions();
            if (collation != null) {
                countOptions.collation(collation);
            }

            count = mongoQuery == null
                    ? collection.countDocuments()
                    : collection.countDocuments(mongoQuery, countOptions);
        }
        return count;
    }
```

```
public long count() {
        if (count == null) {
            Bson query = getQuery();
            CountOptions countOptions = new CountOptions();
            if (collation != null) {
                countOptions.collation(collation);
            }

            count = clientSession == null
                    ? collection.countDocuments(query, countOptions)
                    : collection.countDocuments(clientSession, query, countOptions);
        }
        return count;
    }
```

Here is the [PR](https://github.com/quarkusio/quarkus/pull/27062), let me know if I need to change something.

Best regards.

### Expected behavior

_No response_

### Actual behavior

_No response_

### How to Reproduce?

_No response_

### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

_No response_

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

_No response_

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

_No response_

### Additional information

_No response_

Changed files:
integration-tests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/test/TestResource.java
extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/runtime/CommonReactivePanacheQueryImpl.java
extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/CommonPanacheQueryImpl.java

diff --git a/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/runtime/CommonReactivePanacheQueryImpl.java b/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/runtime/CommonReactivePanacheQueryImpl.java
index 11e71dea326..3e80f4f63f3 100644
--- a/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/runtime/CommonReactivePanacheQueryImpl.java
+++ b/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/runtime/CommonReactivePanacheQueryImpl.java
@@ -9,6 +9,7 @@
 
 import com.mongodb.ReadPreference;
 import com.mongodb.client.model.Collation;
+import com.mongodb.client.model.CountOptions;
 
 import io.quarkus.mongodb.FindOptions;
 import io.quarkus.mongodb.panache.common.runtime.MongoPropertyUtil;
@@ -154,7 +155,14 @@ public <T extends Entity> CommonReactivePanacheQueryImpl<T> withReadPreference(R
     @SuppressWarnings("unchecked")
     public Uni<Long> count() {
         if (count == null) {
-            count = mongoQuery == null ? collection.countDocuments() : collection.countDocuments(mongoQuery);
+            CountOptions countOptions = new CountOptions();
+            if (collation != null) {
+                countOptions.collation(collation);
+            }
+
+            count = mongoQuery == null
+                    ? collection.countDocuments()
+                    : collection.countDocuments(mongoQuery, countOptions);
         }
         return count;
     }
diff --git a/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/CommonPanacheQueryImpl.java b/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/CommonPanacheQueryImpl.java
index 73b112ddc07..8ff48b6abd5 100644
--- a/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/CommonPanacheQueryImpl.java
+++ b/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/CommonPanacheQueryImpl.java
@@ -16,6 +16,7 @@
 import com.mongodb.client.MongoCollection;
 import com.mongodb.client.MongoCursor;
 import com.mongodb.client.model.Collation;
+import com.mongodb.client.model.CountOptions;
 
 import io.quarkus.panache.common.Page;
 import io.quarkus.panache.common.Range;
@@ -157,7 +158,14 @@ public <T extends Entity> CommonPanacheQueryImpl<T> withReadPreference(ReadPrefe
     public long count() {
         if (count == null) {
             Bson query = getQuery();
-            count = clientSession == null ? collection.countDocuments(query) : collection.countDocuments(clientSession, query);
+            CountOptions countOptions = new CountOptions();
+            if (collation != null) {
+                countOptions.collation(collation);
+            }
+
+            count = clientSession == null
+                    ? collection.countDocuments(query, countOptions)
+                    : collection.countDocuments(clientSession, query, countOptions);
         }
         return count;
     }
diff --git a/integration-tests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/test/TestResource.java b/integration-tests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/test/TestResource.java
index 9d8d4cea807..7af7c72c510 100644
--- a/integration-tests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/test/TestResource.java
+++ b/integration-tests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/test/TestResource.java
@@ -113,6 +113,16 @@ public Response testImperativeEntity() {
         Assertions.assertEquals("aaa", results.get(0).title);
         Assertions.assertEquals("AAA", results.get(1).title);
         Assertions.assertEquals("BBB", results.get(2).title);
+
+        //count with collation
+        collation = Collation.builder()
+                .locale("en")
+                .collationStrength(CollationStrength.SECONDARY)
+                .build();
+        Assertions.assertEquals(2, TestImperativeEntity.find("{'title' : ?1}", "aaa").withCollation(collation).count());
+        Assertions.assertEquals(2, TestImperativeEntity.find("{'title' : ?1}", "AAA").withCollation(collation).count());
+        Assertions.assertEquals(1, TestImperativeEntity.find("{'title' : ?1}", "bbb").withCollation(collation).count());
+        Assertions.assertEquals(1, TestImperativeEntity.find("{'title' : ?1}", "BBB").withCollation(collation).count());
         entityAUpper.delete();
         entityALower.delete();
         entityB.delete();
@@ -264,6 +274,17 @@ public Response testImperativeRepository() {
         Assertions.assertEquals("aaa", results.get(0).title);
         Assertions.assertEquals("AAA", results.get(1).title);
         Assertions.assertEquals("BBB", results.get(2).title);
+
+        //count with collation
+        collation = Collation.builder()
+                .locale("en")
+                .collationStrength(CollationStrength.SECONDARY)
+                .build();
+
+        Assertions.assertEquals(2, testImperativeRepository.find("{'title' : ?1}", "aaa").withCollation(collation).count());
+        Assertions.assertEquals(2, testImperativeRepository.find("{'title' : ?1}", "AAA").withCollation(collation).count());
+        Assertions.assertEquals(1, testImperativeRepository.find("{'title' : ?1}", "bbb").withCollation(collation).count());
+        Assertions.assertEquals(1, testImperativeRepository.find("{'title' : ?1}", "BBB").withCollation(collation).count());
         testImperativeRepository.delete(entityALower);
         testImperativeRepository.delete(entityAUpper);
         testImperativeRepository.delete(entityB);
@@ -494,6 +515,20 @@ public Response testReactiveEntity() {
         Assertions.assertEquals("aaa", results.get(0).title);
         Assertions.assertEquals("AAA", results.get(1).title);
         Assertions.assertEquals("BBB", results.get(2).title);
+
+        //count with collation
+        collation = Collation.builder()
+                .locale("en")
+                .collationStrength(CollationStrength.SECONDARY)
+                .build();
+        Assertions.assertEquals(2, TestReactiveEntity.find("{'title' : ?1}", "aaa").withCollation(collation).count()
+                .await().indefinitely());
+        Assertions.assertEquals(2, TestReactiveEntity.find("{'title' : ?1}", "AAA").withCollation(collation).count()
+                .await().indefinitely());
+        Assertions.assertEquals(1, TestReactiveEntity.find("{'title' : ?1}", "bbb").withCollation(collation).count()
+                .await().indefinitely());
+        Assertions.assertEquals(1, TestReactiveEntity.find("{'title' : ?1}", "BBB").withCollation(collation).count()
+                .await().indefinitely());
         entityAUpper.delete().await().indefinitely();
         entityALower.delete().await().indefinitely();
         entityB.delete().await().indefinitely();
@@ -654,6 +689,20 @@ public Response testReactiveRepository() {
         Assertions.assertEquals("aaa", results.get(0).title);
         Assertions.assertEquals("AAA", results.get(1).title);
         Assertions.assertEquals("BBB", results.get(2).title);
+
+        //count with collation
+        collation = Collation.builder()
+                .locale("en")
+                .collationStrength(CollationStrength.SECONDARY)
+                .build();
+        Assertions.assertEquals(2, testReactiveRepository.find("{'title' : ?1}", "aaa").withCollation(collation).count()
+                .await().indefinitely());
+        Assertions.assertEquals(2, testReactiveRepository.find("{'title' : ?1}", "AAA").withCollation(collation).count()
+                .await().indefinitely());
+        Assertions.assertEquals(1, testReactiveRepository.find("{'title' : ?1}", "bbb").withCollation(collation).count()
+                .await().indefinitely());
+        Assertions.assertEquals(1, testReactiveRepository.find("{'title' : ?1}", "BBB").withCollation(collation).count()
+                .await().indefinitely());
         testReactiveRepository.delete(entityALower).await().indefinitely();
         testReactiveRepository.delete(entityAUpper).await().indefinitely();
         testReactiveRepository.delete(entityB).await().indefinitely();