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

geo operator cheat sheet has wrong syntax for $geoWithin with $center

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • Server_Docs_20231030
    • None
    • manual
    • None

    Description

      http://docs.mongodb.org/manual/reference/operator/query-geospatial/#geospatial-query-compatibility

      This page says to use:

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

      But this is invalid syntax:

      > db.generated.find({ "location.coordinates": { $geoWithin: {$center: [40, 7.25], $maxDistance: .01}}})
      error: {
      	"$err" : "the first field of $center object must be a location object",
      	"code" : 13656
      }

      This does work:

      > db.generated.find({ "location.coordinates": { $geoWithin: {$center: [[40, 7.25], .01]}}})

      Attachments

        Activity

          People

            sam.kleinman Sam Kleinman (Inactive)
            dan@mongodb.com Daniel Pasette (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 34 weeks, 1 day ago