Used HybridRelations to store user notifications in mongoDB instead of mysql and imported 3million records and now user->notifications()->take(5)->get() or user->notifications()->paginate(5) takes over 30 seconds. any idea how to speed it up? on mysql with same amount of records it took 200 milliseconds.
notificaiton model has user_id and description and priority and read flag and user_id is set as an index.
Maybe this suggestion can help you.
When use user->notifications()
means the query like that
db.notificaiton.find( {"user_id": <?> } )
That will get all record by user_id.
You can dump the user->notifications()
and check. That should be Collection
type and contains more than 5 records.
The solution is this . You can write specific method to ensure what your mongo query expression.
问题是您排序的列应该是索引以及您使用 where 子句的列。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.