aggregation framework - MongoDB $match inside $cond -
consider following:
db.stores.aggregate( { $project: { _id: 0, in_radius: { $cond: { if: <geowithinexpression>, then: 1, else: 0 } } } })
geowithinexpression actually:
$match: { location: { $geowithin: { $center: [[lat, lon], radius] } } }
i'm doing can use $group on result set counting number of stores in radius. (i'm using $project since want more custom columns 1 , return them in 1 time).
is possible?
this not possible number of reasons quite reasonable really.
while see trying achieve, basic premise
$match
identifier pipeline stage in , therefore can used way.the second case here seem looking sort of "operator" return
$geowithin
type of result in logical (true/false) way used in$project
or$group
stage. falls on concept "geo-spatial" queries require index used, , reason place in aggregation pipeline can make use of index first stage, typically "should"$match
stage.
as stated, concept quite reasonable @ no other time initial pipeline stage going have matches document on index created. new document "copies" exist within pipeline processing , therefore not have associated index.
while clear intention to "test" data locations within various sets, best approach use several queries , combine results in code or otherwise write out collection.
Comments
Post a Comment