An annotation processor for spring-data-mongodb document classes.
- generates meta model for all classes annotated with
@Document
- enables creation of stringless queries
Take a look on an example project.
In order to use this processor add repository location into your pom.xml
and add appropriate dependency.
</dependencies>
<dependency>
<groupId>net.exacode.spring.data.mongodb</groupId>
<artifactId>spring-data-mongodb-processor</artifactId>
<version>${spring-data-mongodb-processor.version}</version>
</dependency>
</dependencies>
Although there is also a second configuration option, the first one is more IDE friendly.
Using this annotation processor and spring-data-mongodb you can create stringless queries like:
// Simple fields:
Criteria.where(User_.email).is(email);
// Instead of: Criteria.where("user.email").is(email);
// Nested documents:
Criteria.where(User_.details.address).is(address);
// Instead of: Criteria.where("user.details.address").is(address);
// Arrays:
Criteria.where(User_.settings.index(5));
// Instead of: Criteria.where("user.settings.5");
- QueryDSL can be used only in queries. What about updating and deleting data?
- QueryDSL comes with a bunch of dependencies. Do we really need them? Our need is simple - just generate meta model in order to replace string queries.
- In application that uses spring-data-mongodb, QueryDSL is a kind of a second (duplicated) way of querying data. I know that QueryDSL predicates are quite handy but I would like all project queries to use the same mechanism. Moreover sytax used in pure spring-data-mongodb is much more similar to MongoDB shell syntax.
- How can I use QueryDSL mechanism with plain MonogoTemplate?
- QueryDSL have some minor problems with querying arrays of nested documents in QueryDSL. For example it's impossible to create such a query:
db.inventory.find( { 'memos.0.by': 'shipping' } )
(see MongoDB doc: match-a-field-in-the-subdocument-using-the-array-index)
Maybe some of these arguments come from my lack of knowledge. Maybe I didn't study the documentation as hard as I should. If I am wrong please correct me.