[CSHARP-2441] LinqToMongo.Inject does not work with 2dsphere Created: 27/Nov/18  Updated: 10/Dec/18  Resolved: 10/Dec/18

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.7.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Frederic Samson [X] Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

We used to be able to do the following in version 2.4 :

 

var filter = Query<TEntity>.Near(field, point, rangeInMeters);
var query = collection.AsQueryable().Where(x => locationClause.Inject());

Now in 2.7, when we do this :

 

var filter = Builders<TEntity>.Filter.Near(field, point, rangeInMeters);
var query = collection.AsQueryable().Where(x => filter.Inject());

we get the following error:

$near is not allowed inside of a $match aggregation

 

Query being injected:

{ "$match" : { "Location" : { "$near" : { "$geometry" : { "type" : "Point", "coordinates" : [-73.656500000000008, 45.567100000000003] }, "$maxDistance" : 10000.0 } } } }

 

 



 Comments   
Comment by Ian Whalen (Inactive) [ 10/Dec/18 ]

Hi Freddy240, the old LINQ was based on Find() while the new implementation is based on Aggregate(), and Server aggregation does not support $near inside of a $match. Given that we do not plan to revert to using Find() in LINQ, this is not something we will be able to fix unless the Server adds support for it.

You could work around this using Find().

Comment by Ronaldo Martinez [ 05/Dec/18 ]

+1 I'd like to keep using IQueryable but because of this i can't.

Generated at Wed Feb 07 21:42:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.