MongoDB —— $unwind 之后的操作 无法使用index, so 后期的 sort,match,分页 无法使用index进行 =》 if 数据量大, then 内存超限异常

after $unwind the index is not useful anymore, the index only useful before $unwind, so it will be a problem when use $match, $sort, $skip after $unwind if the data volume is big.
https://stackoverflow.com/questions/53478941/it-it-possible-to-make-unwind-fast-in-mongodb-by-having-an-index

 

 

$unwind will just iterate on all the elements in an array for each document, and will expend them to a different documentsIndex cannot help you here, the only thing you can do is (as mentioned above) filter the results as much as possible before the unwind stage, or consider storing your data in a different format (not in arrays)

 

posted @ 2023-01-10 10:38  PanPan003  阅读(83)  评论(0编辑  收藏  举报