假设我有 tx_collection 有 3 个文档,如下所示
{
"block_number": 1,
"value": 122
"transfers": [
{
"from": "foo1",
"to": "bar1",
"amount": 111
},
{
"from": "foo3",
"to": "bar3",
"amount": 11
},
]
},
{
"block_number": 2,
"value": 88
"transfers": [
{
"from": "foo11",
"to": "bar11",
"amount": 33
},
{
"from": "foo22",
"to": "bar22",
"amount": 55
},
]
},
{
"block_number": 3,
"value": 233
"transfers": [
{
"from": "foo1",
"to": "bar1",
"amount": 33
},
{
"from": "foo3",
"to": "bar3",
"amount": 200
},
]
}
对于性能问题,我在transfers.amount
当我排序时transfers.amount
,
db.getCollection('tx_transaction').find({}).sort({"transfers.amount":-1})
我期望的文档顺序是按子字段的最大值排序transfers.amount
的
{
"block_number": 3,
"value": 233
"transfers": [
{
"from": "foo1",
"to": "bar1",
"amount": 33
},
{
"from": "foo3",
"to": "bar3",
"amount": 200
},
]
},
{
"block_number": 1,
"value": 122
"transfers": [
{
"from": "foo1",
"to": "bar1",
"amount": 111
},
{
"from": "foo3",
"to": "bar3",
"amount": 11
},
]
},
{
"block_number": 2,
"value": 88
"transfers": [
{
"from": "foo11",
"to": "bar11",
"amount": 33
},
{
"from": "foo22",
"to": "bar22",
"amount": 55
},
]
}
由于只有 3 个文档,因此排序效果很好。排序顺序是我期望的块号 3 -> 块号 1 -> block_number 2
我的问题是,当有 1900 万个文档时,它会抛出错误消息
按摩就像
"errmsg" : "Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.",
排序时似乎没有使用多键索引。
你知道为什么会抛出这个错误信息吗?
JFYI。
- 我的 mongodb 版本是 3.6.3
- tx_collection 被分片