Skip to content

Replace usage of deprecated collection.count() with collection.countDocuments() [DATAMONGO-2059] #2925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Aug 16, 2018 · 3 comments
Assignees
Labels
in: core Issues in core support type: task A general task

Comments

@spring-projects-issues
Copy link

Christoph Strobl opened DATAMONGO-2059 and commented

sessionBound.query(Person.class)
    .matching(query(where("location")
        .near(new Point(1, 0)))

fails with

error 2 (BadValue): $match does not support $geoNear, $near, and $nearSphere

we need to switch over to $geoWithin using $center


Reference URL: https://jira.mongodb.org/browse/DRIVERS-518

Issue Links:

  • DATAMONGO-2192 Improve count() and countDocuments() mapping documentation and/or method availability

Referenced from: pull request #604

@spring-projects-issues
Copy link
Author

Mark Paluch commented

This is a known issue and we spiked on possible ways how to address MongoDB's behavior. Right now we're recommending to use geoWithin query operators (in criteria Query and repository query methods) when using Client Sessions and count-based queries

@spring-projects-issues
Copy link
Author

Doron Levari commented

We are getting KILLED by Mongo 4.0 doing count instead of countDocuments. We are already using 2.2.4. Any chance this can backport to 2.2.X?

Any workaround you may think of until 3.0 gets out? When is that planned?

Thanks!!

See below a slow q log from Mongo, stupid count, there are 7 docs in the "device" collection... 7!!! (2 are configState: "NOT_SYNCED") and the count takes 97 seconds because of "schemaLock"... Please help!!

2020-03-05T14:14:48.589+0000 I COMMAND  [conn2198692] command XYZ.device command: count { count: "device", query: { configState: "NOT_SYNCED" }, $db: "XYZ", $clusterTime: { clusterTime: Timestamp(1583417583, 16), signature: { hash: BinData(0, 09E81DF60CD75D49362F7838374CE05FF94C82A6), keyId: 6753496676054335795 } }, lsid: { id: UUID("25508109-bce4-4554-af76-5fd3cc099052") } } planSummary: COUNT_SCAN { configState: 1 } keysExamined:1 docsExamined:0 numYields:0 reslen:170 locks:{ Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } } } storage:{ timeWaitingMicros: { handleLock: 14705, schemaLock: 97085560 } } protocol:op_msg 97101ms

 

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

Please find planned release dates in our wiki or the Spring Calendar.
A backport is rather unlikely. We need to see if we can do something about this for the 2.2.x line

@spring-projects-issues spring-projects-issues added in: core Issues in core support type: task A general task labels Dec 30, 2020
christophstrobl added a commit that referenced this issue Mar 23, 2022
$near and $nearSphere queries are not supported via countDocuments and the used aggregation match stage and need to be rewritten to $geoWithin. The existing logic did not cover usage of geoJson types, which is fixed now. In case of nearSphere it is also required to convert the $maxDistance argument (given in meters for geoJson) to radians which is used by $geoWithin $centerSphere.

Related to #2925
mp911de pushed a commit that referenced this issue Sep 21, 2022
$near and $nearSphere queries are not supported via countDocuments and the used aggregation match stage and need to be rewritten to $geoWithin. The existing logic did not cover usage of geoJson types, which is fixed now. In case of nearSphere it is also required to convert the $maxDistance argument (given in meters for geoJson) to radians which is used by $geoWithin $centerSphere.

Closes #4004
Original pull request: #4006.
Related to #2925
mp911de pushed a commit that referenced this issue Sep 21, 2022
$near and $nearSphere queries are not supported via countDocuments and the used aggregation match stage and need to be rewritten to $geoWithin. The existing logic did not cover usage of geoJson types, which is fixed now. In case of nearSphere it is also required to convert the $maxDistance argument (given in meters for geoJson) to radians which is used by $geoWithin $centerSphere.

Closes #4004
Original pull request: #4006.
Related to #2925
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants