Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-635

weird update $push $sort behavior

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Python 2.7.2+

      when I try to use update with $push and $sort to add to the array field, the result(order of the element in the array) seems to be different according to the type of the element in the original array.

      The following are my test cases, they are pretty much identical, the only difference is the array D is a OrderedDict for the second test. And the results of the two tests are different that the elements order in the array D got reversed.

      coll.remove()
      coll.save({ 'D': [ { 'D': None, 'C': 1, } ] })
      coll.update({}, {'$push': {'D': {'$each': [{'1': 0}], '$sort': 1}}}, upsert=False, multi=False)
      coll.find_one()
      

      I got the following result:

      {u'_id': ObjectId('52f54c8fa0cc2b2484cd578f'), u'D': [{u'1': 0}, {u'C': 1, u'D': None}]}
      
      coll.remove()
      coll.save({ 'D': [ OrderedDict([( 'D',None), ('C', 1)] )] })
      coll.update({}, {'$push': {'D': {'$each': [{'1': 0}], '$sort': 1}}}, upsert=False, multi=False)
      coll.find_one()
      

      I got the following result:

      {u'_id': ObjectId('52f54c98a0cc2b2484cd5790'), u'D': [{u'C': 1, u'D': None}, {u'1': 0}]}
      

      Could you please let me know how this can affect the result of the $sort?
      Thanks,
      -Steve

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            sduan Steve Duan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: