Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-2247

geo query with regex against an array returns no results

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 1.9.0
    • 1.6.5
    • Geo
    • None
    • Linux

    Description

      Here's an example using pymongo. I'm able to duplicate with different types of geo queries:

      import re
      from pymongo import Connection

      coll = Connection().test.georegexlistfail
      coll.ensure_index([('point', '2d'), ('words', 1)])
      coll.insert({
      'point': [1, 1],
      'words': ['foo', 'bar']
      })

      q_regex =

      {'words': re.compile('^f')}

      q_geo = {'point': {'$near':[1,1]}}
      q_both =

      {'words': q_regex['words'], 'point': q_geo['point']}

      def run(q):
      print 'Query: %s' % str(q)
      print 'Result: %s' % str(coll.find_one(q))
      print

      run(q_regex)
      run(q_geo)
      run(q_both)

      """
      Output:

      Query:

      {'words': <_sre.SRE_Pattern object at 0x7f9fc21b63b0>}

      Result:

      {u'_id': ObjectId('4d0be668b45b5d4d2d000000'), u'words': [u'foo', u'bar'], u'point': [1, 1]}

      Query: {'point': {'$near': [1, 1]}}
      Result:

      {u'_id': ObjectId('4d0be668b45b5d4d2d000000'), u'words': [u'foo', u'bar'], u'point': [1, 1]}

      Query: {'words': <_sre.SRE_Pattern object at 0x7f9fc21b63b0>, 'point': {'$near': [1, 1]}}
      Result: None
      """

      Thanks!

      Attachments

        Activity

          People

            greg_10gen Greg Studer
            elisha Elisha Cook
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: