GitHub user kb1ca opened a pull request: https://github.com/apache/camel/pull/1016
Consider sortBy header when performing findOneByQuery operation There is a often a requirement to fetch the min/max record from Mongo based on a particular field. Typically the operation is performed using syntax similar to: db.collection.find().sort({_id: -1}).limit(1) or db.collection.findOne({$query:{},$orderby:{_id:-1}}) As implemented the findOneByQuery operation currently ignores the sortBy header. This trivial patch passes sortBy to the sort parameter of findOne(), if set. Helpfully, if the projection parameter is null findOne() returns all fields, so the state of fieldFilter is not checked before passing when the sortBy header has been set. You can merge this pull request into a Git repository by running: $ git pull https://github.com/kb1ca/camel camel-2.17.x Alternatively you can review and apply these changes as the patch at: https://github.com/apache/camel/pull/1016.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #1016 ---- commit 1ae1ad31f003148dde8df84442ddfc78c57589f9 Author: Kris Boutilier <kris.boutil...@gmail.com> Date: 2016-06-06T23:56:42Z Consider sortBy header when performing findOneByQuery operation ---- --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---