hibernate/hibernate-ogm — pull request #327 by gunnarmorling (2014-06-03 09:22:27+00:00)
Title: OGM-513 Support for projections and count() in native MongoDB queries

@emmanuelbernard, @DavideD: Can you guys let me know what you think. This PR allows to do the following queries in MongoDB:

String nativeQuery = "db.WILDE_POEM.find( "
+ "{ '$and' : [ { 'name' : 'Portia' }, { 'author' : 'Oscar Wilde' } ] }, "
+ "{ 'name' : 1 }"
+ " )";

String nativeQuery = "db.WILDE_POEM.count()";

My primary motivation is adding support for `count()` to facilitate paging use cases, hence I didn't add any further operations besides the two, but it could rather easily be done in further iterations.

Working on projections, I noticed that we do not yet apply type conversion of selected scalar values (see [OGM-546](https://hibernate.atlassian.net/browse/OGM-546)), so the usefulness of projections seems a bit limited.

I still feel it'd make sense to integrate this PR already as it gives support for count (no conversion required here), it straightens out some things and it paves the road for further changes (e.g. native update queries). If we agree on the direction, I'll update the MongoDB chapter of the docs.