c# - MongoDB .NET exception: Unsupported filter -
i using .net wrapper mongodb (refer following excerpt packages.config versions):
<package id="mongocsharpdriver" version="2.4.2" targetframework="net461" /> <package id="mongodb.bson" version="2.4.2" targetframework="net461" /> <package id="mongodb.driver" version="2.4.2" targetframework="net461" /> <package id="mongodb.driver.core" version="2.4.2" targetframework="net461" />
i trying build simple filter obtain items of location's latitude , longitude within limits defined latitudedelta , longitudedelta.
bool filterall = string.isnullorempty(username) || username == "*"; var filter = builders<models.mapquery>.filter.where(p => (filterall || (username == p.creatorusername)) && math.abs(p.pinlocation.latitude - desiredlatitude) < latitudedelta && math.abs(p.pinlocation.longitude - desiredlongitude) < longitudedelta); var queries = await db.getcollection<models.mapquery>(constants.map_query) .find(filter) .tolistasync();
when program executes "var queries" line, hit exception saying "abs(({pinlocation.latitude} - 3.209096)) not supported.".
how fix above exception? otherwise, workaround if above problem cannot solved?
maby works?
var filter = builders<models.mapquery>.filter.and( builders<models.mapquery>.filter.eq(p => p.username, username), builders<models.mapquery>.filter.lt(p => math.abs(p.pinlocation.latitude - desiredlatitude), latitudedelta), builders<models.mapquery>.filter.lt(p => math.abs(p.pinlocation.longitude - desiredlongitude), longitudedelta));
i changed code use built in api calls more readability. suggest first check before executing query.
Comments
Post a Comment