[DOCS-1390] Comment on: "manual/reference/operator/sort.txt" Created: 12/Apr/13  Updated: 03/Nov/17  Resolved: 17/Apr/13

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: auto Assignee: Barrie Segal
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OS X 10.8 with MongoDB 2.4.1

Location: http://docs.mongodb.org/manual/reference/operator/sort/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.28.10 (KHTML, like Gecko) Version/6.0.3 Safari/536.28.10
Referrer: http://docs.mongodb.org/manual/reference/operator/setOnInsert/
Screen Resolution: 1920 x 1200
repo: docs
source: reference/operator/sort


Participants:
Days since reply: 10 years, 44 weeks, 5 days ago

 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 }

}
]
}


Generated at Thu Feb 08 07:40:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.