How can I make query with sorting by an array of string which will be execute without "stage" : "SORT"
in its plan?
I'm using mongo 3.6
"mycoll" collection contains about 500.000 documents like these:
{
someobject:{
arrayfield:["asd","qwe"]
}
}
{
someobject:{
arrayfield:["zxc"]
}
}
this query
db.mycoll.find().sort({ "someobject.arrayfield": 1 }).skip(125340).limit(20)
produces an error
Sort operation used more than the maximum 33554432 bytes of RAM
I have and index on "someobject.arrayfield",but explain() gives me:
"winningPlan" : {
"stage" : "SKIP",
"skipAmount" : 125340,
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"someobject.arrayfield" : 1
},
"limitAmount" : 125360,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"someobject.arrayfield" : 1
},
"indexName" : "arrayfield_indexname",
"isMultiKey" : true,
"multiKeyPaths" : {
"someobject.arrayfield" : [
"someobject.arrayfield"
]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"someobject.arrayfield" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
}
I know, I can increase the limits, use aggregation with 'allowdiskusage' or query
db.mycoll.find().sort({ "someobject.arrayfield.1": 1 }).skip(125340).limit(20)
with index on "someobject.arrayfield.1"