-
Type:
Bug
-
Resolution: Gone away
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
When calling "count" on a Criteria that includes $near, I get the error, "Mongo::Error::OperationFailure Exception: $geoNear, $near, and $nearSphere are not allowed in this context (2)".
I noticed this issue when upgrading from Mongoid 7.0.2 to 7.2.2. Previously, the count was returned correctly.
A behavior difference I notice is that with mongoid 7.2.2 the query is turned into an aggregation. Previously, this was a regular count command.
Example aggregation sent to the server:
{
aggregate: "college_listings",
pipeline: [
{
$match: {
active_in_search: true,
loc: {$near: [20, 20]},
$and: [{loc: {$near: [20, 20]}}]
}
},
{$group: {_id: 1, n: {$sum: 1}}}
],
cursor: {},
$db: "raise-test",
lsid: {id: UUID("0fc75d31-449b-4fd6-ad70-1284c0b57808")}
}
Ruby code:
class CollegeListing include Mongoid::Document field :loc, type: Array end CollegeListing.where(loc: { '$near' => [20, 20] }).count
- related to
-
SERVER-57932 Improve error message for $near in aggregation to suggest workarounds
-
- Closed
-