NOsql Object (NO2 a.k.a Nitrite) database is an open source nosql embedded document store written in Java. It has MongoDB like API. It supports both in-memory and single file based persistent store powered by MVStore engine of h2 database.

Nitrite is a server-less embedded database ideal for desktop, mobile or small web applications.

It features: - Embedded key-value/document and object store - In-memory or single data file - Very fast and lightweight MongoDB like API - Indexing - Full text search capability - Full Android compatibility - Observable store - Both way replication via Nitrite DataGate server

Programming language: Java
License: Apache License 2.0
Tags: Database     Libraries     Java     NoSQL    
Latest version: v3.4.3

Nitrite Database alternatives and similar packages

Based on the "Database" category.
Alternatively, view Nitrite Database alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Nitrite Database or a related project?

Add another 'Database' Package


Nitrite Database

Build CodeQL Codacy codecov Javadocs Discussion Backers on Open Collective Backers on Open Collective Gitpod ready-to-code

NOsql Object (NO2 a.k.a Nitrite) database is an open source nosql embedded document store written in Java. It has MongoDB like API. It supports both in-memory and file based persistent store.

Nitrite is an embedded database ideal for desktop, mobile or small web applications.

It features:

  • Schemaless document collection and object repository
  • In-memory / file-based store
  • Pluggable storage engines - mvstore, mapdb, rocksdb
  • ACID transaction
  • Schema migration
  • Indexing
  • Full text search
  • Both way replication via Nitrite DataGate server
  • Very fast, lightweight and fluent API
  • Android compatibility (API Level 19)

Kotlin Extension

Nitrite has a kotlin extension called Potassium Nitrite for kotlin developers. Visit here for more details.

Getting Started with Nitrite

NOTE: There are breaking api changes in version 4.x.x. So please exercise caution when upgrading from 3.x.x
especially for package name changes.

How To Install

To use Nitrite in any Java application, first add the nitrite bill of materials, then add required dependencies:







implementation 'org.dizitart:nitrite'
implementation 'org.dizitart:nitrite-mvstore-adapter'

Quick Examples

Initialize Database

// create a mvstore backed storage module
MVStoreModule storeModule = MVStoreModule.withConfig()
    .filePath("/tmp/test.db")  // for android - .filePath(getFilesDir().getPath() + "/test.db")

// or a rocksdb based storage module
RocksDBModule storeModule = RocksDBModule.withConfig()

// initialization using builder
Nitrite db = Nitrite.builder()
        .loadModule(new JacksonMapperModule())  // optional
        .openOrCreate("user", "password");

Create a Collection

// Create a Nitrite Collection
NitriteCollection collection = db.getCollection("test");

// Create an Object Repository
ObjectRepository<Employee> repository = db.getRepository(Employee.class);

Annotations for POJO

@Entity(value = "retired-employee",     // entity name (optional), 
    indices = {
        @Index(value = "firstName", type = IndexType.NonUnique),
        @Index(value = "lastName", type = IndexType.NonUnique),
        @Index(value = "note", type = IndexType.Fulltext),
public class Employee implements Serializable {
    // provides id field to uniquely identify an object inside an ObjectRepository
    private long empId;
    private Date joinDate;
    private String firstName;
    private String lastName;
    private String note;

    // ... public getters and setters

CRUD Operations

// create a document to populate data
Document doc = createDocument("firstName", "John")
     .put("lastName", "Doe")
     .put("birthDay", new Date())
     .put("data", new byte[] {1, 2, 3})
     .put("fruits", new ArrayList<String>() {{ add("apple"); add("orange"); add("banana"); }})
     .put("note", "a quick brown fox jump over the lazy dog");

// insert the document

// find a document

// update the document
collection.update(where("firstName").eq("John"), createDocument("lastName", "Wick"));

// remove the document

// insert an object in repository
Employee emp = new Employee();


Create Indices

// create document index
collection.createIndex("firstName", indexOptions(IndexType.NonUnique));
collection.createIndex("note", indexOptions(IndexType.Fulltext));

// create object index. It can also be provided via annotation
repository.createIndex("firstName", indexOptions(IndexType.NonUnique));

Query a Collection

DocumentCursor cursor = collection.find(
    where("firstName").eq("John")               // firstName == John
        where("data").elemMatch("$".lt(4))      // AND elements of data array is less than 4
                where("note").text("quick")     // AND note field contains string 'quick' using full-text index

for (Document document : cursor) {
    // process the document

// get document by id
Document document = collection.getById(nitriteId);

// query an object repository and create the first result
Cursor<Employee> cursor = repository.find(where("firstName").eq("John"));
Employee employee = cursor.firstOrNull();


try (Session session = db.createSession()) {
    Transaction transaction = session.beginTransaction();
    try {
        NitriteCollection txCol = transaction.getCollection("test");

        Document document = createDocument("firstName", "John");

    } catch (TransactionException e) {

Schema Migration

Migration migration1 = new Migration(Constants.INITIAL_SCHEMA_VERSION, 2) {
    public void migrate(InstructionSet instructions) {
            // make a non-secure db to secure db
            .addPassword("test-user", "test-password");

        // create instructions for existing repository
        instructions.forRepository(OldClass.class, null)

            // rename the repository (in case of entity name changes)
            .renameRepository("migrated", null)

            // change datatype of field empId from String to Long and convert the values
            .changeDataType("empId", (TypeConverter<String, Long>) Long::parseLong)

            // change id field from uuid to empId
            .changeIdField("uuid", "empId")

            // delete uuid field

            // rename field from lastName to familyName
            .renameField("lastName", "familyName")

            // add new field fullName and add default value as - firstName + " " + lastName
            .addField("fullName", document -> document.get("firstName", String.class) + " "
                + document.get("familyName", String.class))

            // drop index on firstName

            // drop index on embedded field literature.text

            // change data type of embedded field from float to integer and convert the values 
            .changeDataType("literature.ratings", (TypeConverter<Float, Integer>) Math::round);

Migration migration2 = new Migration(2, 3) {
    public void migrate(InstructionSet instructions) {
            .addField("fullName", "Dummy Name");

MVStoreModule storeModule = MVStoreModule.withConfig()

db = Nitrite.builder()

    // schema versioning is must for migration

    // add defined migration paths
    .addMigrations(migration1, migration2)

Automatic Replication

NitriteCollection collection = db.getCollection("products");

Replica replica = Replica.builder()
    // replication via websocket (ws/wss)
    // user authentication via JWT token
    .jwtAuth("john", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c")


Import/Export Data

// Export data to a file
Exporter exporter = Exporter.of(db);

//Import data from the file
Importer importer = Importer.of(db);

More details are available in the reference document.

Release Notes

Release notes are available here.


Reference API Document JavaDoc


To build and test Nitrite

```shell script

git clone https://github.com/nitrite/nitrite-java.git cd nitrite-java ./gradlew build

## Support / Feedback

For issues with, questions about, or feedback talk to us at [Gitter](https://gitter.im/nitrite-db/nitrite-java).

## Bugs / Feature Requests

Think you’ve found a bug? Want to see a new feature in the Nitrite? Please open an issue [here](https://github.com/nitrite/nitrite-java/issues). But
before you file an issue please check if it is already existing or not.

## Maintainers

-   Anindya Chatterjee

## Contributors

This project exists thanks to all the people who contribute. [Contribute](https://github.com/dizitart/nitrite-database/blob/master/CONTRIBUTING.md).

## Backers

Thank you to all our backers! 🙏 [Become a backer](https://opencollective.com/nitrite-database#backer)


## Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](https://opencollective.com/nitrite-database#sponsor)


## Presentation & Talks

[Idan Sheinberg](https://github.com/sheinbergon) has given a talk on Nitrite at [**Kotlin Everywhere - TLV Edition**](https://www.meetup.com/KotlinTLV/events/265145254/) meetup on October 27, 2019. Please find his presentation [here](https://www.slideshare.net/IdanShinberg/nitrite-choosing-the-rite-embedded-database).

## Special Thanks

<a href="https://www.ej-technologies.com/products/jprofiler/overview.html" style="margin-right: 20px;">
    <img src="https://www.ej-technologies.com/images/product_banners/jprofiler_medium.png" alt="JProfiler"/>

<a href="https://www.yourkit.com/" style="margin-right: 20px;">
    <img src="https://www.yourkit.com/images/yklogo.png" alt="YourKit"/>

<a href="https://www.macstadium.com/" style="margin-right: 30px;">
    <img src="https://uploads-ssl.webflow.com/5ac3c046c82724970fc60918/5c019d917bba312af7553b49_MacStadium-developerlogo.png" height="32" alt="MacStadium"/>