Skip to content

hexwit/ninja-jongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB module for Ninja framework

Overview

This module filling the gap between Ninja framework and MongoDB. In a few simple steps you can integrate MongoDB support into your application. Beside this you get automatic object mapping provided by Jongo and Jackson libraries.

Setup

Add module dependency to you pom.xml:

<dependency>
    <groupId>com.hexwit.ninja.jongo</groupId>
    <artifactId>ninja-jongo-module</artifactId>
    <version>1.0.0</version>
</dependency>

Install the module in your conf.Module:

protected void configure() {
    // This installs the NinjaModule and handles the lifecycle
    install(new NinjaJongoModule());
}

Configuration

Add MongoDB connection url to your application.conf file like:

mongodb.uri=mongodb://localhost:27017/dbname 

See connection string URI format on the MongoDB official site.

Usage

To get access to mongo's collections you need just ask for injection, and provide collection name:

@Singleton
public class UserDAO {
    @InjectMongoCollection(name = "users")
    MongoCollection users;

    public User getById(String userId) {
        return users.findOne("{_id: #}", new ObjectId(userId)).as(User.class);
    }
    
    public boolean isEmailRegistered(String email) {
        return users.count("{email: #}", email) > 0;
    }
}

References

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages