GitHub user kb1ca opened a pull request: https://github.com/apache/camel/pull/1013
Evalute sortBy header as part of 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 master Alternatively you can review and apply these changes as the patch at: https://github.com/apache/camel/pull/1013.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 #1013 ---- commit a1014d0ef6d0eadab46ffb8d0c06c669b3b0c18a Author: Kris Boutilier <kris.boutil...@gmail.com> Date: 2016-06-03T16:42:08Z Pass sortBy header to sort parameter of findOne() if defined in addition to a fieldFilter header. Ignore sortBy and log debug message if passed a sortBy without fieldFilter. commit 9e4809de92d39548191b58e6a6c11ab4c9b85846 Author: Kris Boutilier <kris.boutil...@gmail.com> Date: 2016-06-03T17:16:57Z Add support for sortBy header to findOneByQuery operation. commit c29154525f4c951821c232997136c0e6b24d089a Author: Kris Boutilier <kris.boutil...@gmail.com> Date: 2016-06-03T17:22:58Z Merge remote-tracking branch 'origin/master' Conflicts: components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java ---- --- 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. ---