Mongo: aggregate $geoNear and $text no results

前端 未结 2 928
北恋
北恋 2021-01-16 02:39

I\'m trying to do a geoNear + text search aggregate query in Mongoose:

landmarkSchema.aggregate(
   [
      { \"$geoNear\": {
        \"near\": {
          \         


        
2条回答
  •  悲哀的现实
    2021-01-16 02:55

    Alternatively to @wdberkeley's answer, you can use $geoWithin instead of the $geoNear stage.

    db.landmarkSchema.aggregate([
      {$match: {
          $text: {$search: "great test text"} ,
          loc: {$geoWithin: {$centerSphere: [[ 14.3, 48.3], 5/6731]}}
      }}])
    

    Note: The geo index won't be used!

    More information: http://docs.mongodb.org/manual/reference/operator/query/geoWithin/

提交回复
热议问题