Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-1653

Comment on: "manual/reference/operator/query-geospatial.txt"

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None

    Description

      The example for $geoWithin with $center is not correct:

      { $geoWithin : {
        $center : [x1, y1],
        $maxDistance : d
      } }

      This is not the right syntax for $center. It doesn't support $maxDistance. That is for the $near operator.

      Trying this in the shell returns:

      > db.docs.find({loc: {$geoWithin: {$center: [15, 15], $maxDistance:10} }})
      error: {
      	"$err" : "Malformed geo query: { $geoWithin: { $center: [ 15.0, 15.0 ], $maxDistance: 10.0 } }",
      	"code" : 16677
      }

      The correct syntax is explained on the $center page:

      { $geoWithin : {
        $center :
          [[x, y], radius]
      } }

      It is the same as the $centerSphere syntax.

      That also works in the shell:

      > db.docs.find({loc: {$geoWithin: {$center: [[15, 15], 10]}}})
      { "_id" : ObjectId("51cbb33a7645edc3cf1057cb"), "loc" : [  10,  20 ] }

      Attachments

        Activity

          People

            sam.kleinman Sam Kleinman (Inactive)
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 33 weeks, 6 days ago