querydsl/querydsl-mongodb
Jan-Willem Gmelig Meyling f6ce863b20
Merge pull request #3254 from sangyongchoi/feature/add-all-ops
add $all operation
2022-10-07 13:18:59 +02:00
..
src add $all operation 2022-04-30 18:06:02 +09:00
pom.xml Introduce japicmp (#2977) 2022-09-14 12:10:29 +02:00
README.md Switch from Slf4j to JUL to reduce transitive dependencies 2021-01-17 15:54:11 +01:00

Querydsl Mongodb

The Mongodb module provides integration with the Mongodb API.

Maven integration

Add the following dependencies to your Maven project :

<dependency>
  <groupId>com.querydsl</groupId>
  <artifactId>querydsl-mongodb</artifactId>
  <version>${querydsl.version}</version>
</dependency>

And now, configure the Maven APT plugin which generates the query types used by Querydsl :

<project>
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>com.mysema.maven</groupId>
        <artifactId>apt-maven-plugin</artifactId>
        <version>1.1.3</version>
        <executions>
          <execution>
            <goals>
              <goal>process</goal>
            </goals>
            <configuration>
              <outputDirectory>target/generated-sources/java</outputDirectory>
              <processor>com.querydsl.mongodb.morphia.MorphiaAnnotationProcessor</processor>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  </build>
</project>

The MorphiaAnnotationProcessor finds domain types annotated with the com.google.code.morphia.annotations.Entity annotation and generates Querydsl query types for them.

Run mvn clean install and you will get your Query types generated into target/generated-sources/java.

If you use Eclipse, run mvn eclipse:eclipse to update your Eclipse project to include target/generated-sources/java as a source folder.

Now you are able to construct Mongodb queries and instances of the query domain model.

Example query

Querying with Querydsl Mongodb with Morphia is as simple as this :

Morphia morphia;
Datastore datastore;
// ...  
QUser user = new QUser("user");
MorphiaQuery<User> query = new MorphiaQuery<User>(morphia, datastore, user);
List<User> list = query
    .where(user.firstName.eq("Bob"))
    .fetch();

For more information on the Querydsl Mongodb module visit the reference documentation http://www.querydsl.com/static/querydsl/latest/reference/html/ch02s07.html