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

Comment on: "manual/reference/operator/sort.txt"

    XMLWordPrintableJSON

Details

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

    Description

      From Python, I do this:

      collection.update(

      {'_id': event_id}

      ,
      {
      '$setOnInsert':

      { 'ip': request.real_ip, 'ts': now }

      ,
      '$push': {
      'entries': {
      '$each': [values],
      '$sort':

      {'ts': 1}

      ,
      '$slice': -5000
      }
      }
      }, upsert=True, safe=False)

      Sometimes this works as expected. Othertimes, with identical input and no change to the code, I get a record full of $slice, $each and $sort elements. Like this:

      {
      "_id": "127.0.0.1/1365794488242",
      "ip": "127.0.0.1",
      "ts": 1365798897.709374,
      "entries": [

      { "name": "value", "name2": "value2", "ts": 1365798897.698 }

      ,

      { "message": "Got here!", "ts": 1365798897.699 }

      ,

      { "name": "value", "name2": "value2", "ts": 1365798933.084 }

      ,

      { "message": "Got here!", "ts": 1365798933.085 }

      ,

      { "name": "value", "name2": "value2", "ts": 1365798965.257 }

      ,

      { "text": "Got here!", "ts": 1365798965.258 }

      ,

      { "ts": 1365799274.568 }

      ,

      { "text": "", "ts": 1365799274.569 }

      ,

      { "counted": "5", "junked": "7", "text": "[object Object]", "ts": 1365799274.57 }

      ,

      { "name": "value", "name2": "value2", "ts": 1365799323.372 }

      ,

      { "text": "", "ts": 1365799323.373 }

      ,

      { "counted": "5", "junked": "7", "text": "[object Object]", "ts": 1365799323.374 }

      ,

      { "name": "value", "name2": "value2", "ts": 1365799363.186 }

      ,

      { "text": "Got here!", "ts": 1365799363.187 }

      ,

      { "counted": "5", "junked": "7", "text": "And here!", "ts": 1365799363.188 }

      , {
      "$slice": -5000,
      "$each": [

      { "name": "value", "name2": "value2", "ts": 1365799632.962 }

      ],
      "$sort":

      { "ts": 1 }

      }, {
      "$slice": -5000,
      "$each": [

      { "text": "Got here!", "ts": 1365799632.963 }

      ],
      "$sort":

      { "ts": 1 }

      }, {
      "$slice": -5000,
      "$each": [

      { "counted": "5", "junked": "7", "text": "And here!", "ts": 1365799632.964 }

      ],
      "$sort":

      { "ts": 1 }

      }, {
      "$slice": -5000,
      "$each": [

      { "name": "value", "name2": "value2", "ts": 1365799750.773 }

      ],
      "$sort":

      { "ts": 1 }

      }, {
      "$slice": -5000,
      "$each": [

      { "text": "Got here!", "ts": 1365799750.774 }

      ],
      "$sort":

      { "ts": 1 }

      }, {
      "$slice": -5000,
      "$each": [

      { "counted": "5", "junked": "7", "text": "And here!", "ts": 1365799750.775 }

      ],
      "$sort":

      { "ts": 1 }

      }
      ]
      }

      Attachments

        Activity

          People

            barrie Barrie Segal
            auto auto
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 44 weeks, 5 days ago