[SERVER-46052] elemMatch in GeoNear query doesn't support indexes Created: 09/Feb/20  Updated: 27/Oct/23  Resolved: 07/Jul/20

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 4.2.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Dennis Smal' Assignee: Dmitry Agranat
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

I use this aggregation for my collection

{
     "$geoNear": {
         "near": {
            "type": "Point",
            "coordinates": [ 38.975313, 45.03547 ],
        },
        "distanceField": "origin.distance",
        "spherical": true,
        "query": {
            "trip": {
                "$elemMatch": {
                    "point.pre": true,
                    "point.departure": \{ "$gt": new Date() }
                }
            }
        }
    }
 }

and this indexes:

db.getCollection('sp_trips').createIndex({
    "trip.point" : "2dsphere",
    "trip.point.pre": 1,
    "trip.point.departure": 1
})

It seems that indexes doesn't work.

 

For testing I created new indexes

db.getCollection('sp_trips').createIndex({
    "trip.point.pre": 1,
    "trip.point.departure": 1
})

and launch command

db.getCollection('sp_trips').find({
    "trip": {
        "$elemMatch": {
            "point.pre": true,
            "point.departure": \{ "$lt": new Date() }
        }
    }
}).count()

This works fine. But If I use elemMatch inside geoNear indexes doesn't work.



 Comments   
Comment by Dmitry Agranat [ 07/Jul/20 ]

Hi verrasmal@gmail.com,

We haven’t heard back from you for some time, so I’m going to mark this ticket as resolved. If this is still an issue for you, please provide additional information and we will reopen the ticket.

Regards,
Dima

Comment by Carl Champain (Inactive) [ 20/Feb/20 ]

verrasmal@gmail.com,

So far we were not able to recreate the described behavior. To help us understand your issue, can you please provide:

  1. An example of a document in the sp_trips collection? We want to make sure that we have recreated the correct schema.
  2. The explain output for the aggregation and the find query? 

Thank you,
Carl
 

Comment by Carl Champain (Inactive) [ 13/Feb/20 ]

Hi verrasmal@gmail.com,

Thanks for the report.
We will investigate your issue and will let you know.

Kind regards,
Carl

Generated at Thu Feb 08 05:10:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.