Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort + limit使用问题 #54

Open
westzbo opened this issue Aug 17, 2016 · 3 comments
Open

sort + limit使用问题 #54

westzbo opened this issue Aug 17, 2016 · 3 comments

Comments

@westzbo
Copy link

westzbo commented Aug 17, 2016

cursor:limit(6)
local sort_res = cursor:sort({startTime=-1}}, 1000)

当最大条目小余limit值,最开始的几条数据不会返回~~这个是怎么回事?

比如最大条目是7,limit为10,则全部返回,limit为5,则最大的两条不会返回

@westzbo
Copy link
Author

westzbo commented Aug 17, 2016

我又查了下底层lua部分,貌似没有实现sort的命令?

@westzbo
Copy link
Author

westzbo commented Aug 18, 2016

找到了一种方式,用db.collection.find( { $query: {}, $orderby: { age : -1 } } )

但是mongodb3.2版本以后就不支持了~
https://docs.mongodb.com/manual/reference/operator/meta/orderby/

@showapicxt
Copy link

确实是用db.collection.find( { $query: {}, $orderby: { age : -1 } } ) 这种方式才有效。limit+sort的问题太多了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants