Nitrite: An Embedded NoSQL Database for Java and Android

Anindya Chatterjee
May 11, 2017 · 2 min read

The NoSQL Object (or NO2, AKA Nitrite) database is an open-source NoSQL embedded document database written in Java with a MongoDB-like API. It supports both in-memory and single file-based persistent stores.

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


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

Nitrite is not an RDBMS. It is also not a distributed NoSQL database like MongoDB or Cassandra. It does not have any server for external applications to connect to. It does not support sharding or ACID transaction.

How to Install

To use Nitrite in any Java application, just add the below dependency:




Let’s now start with some quick examples.

Initialize Database

For more options on opening a database, visit here.

Data in Nitrite is stored as a document in a collection called NitriteCollection. A document is nothing but a map of key-value pairs.

A POJO can also be stored directly in an ObjectRepository. Under the hood, a POJO is converted into a document using Jackson's ObjectMapper and is stored in a NitriteCollection.

Create a Collection

Construct a Document

CRUD operations are very easy and are very much similar to the Mongo Java API.

Insert/Modify/Remove a Document

Details of CRUD operations for NitriteCollection can be found here for ObjectRepository here.

Query a Collection

Nitrite comes with an easy API for querying a collection efficiently.

Nitrite supports indexing. It takes advantage of indexing during searching. More on this can be found here.


In our connected world, seamless replication over devices is a must. Nitrite supports replication with the help of Nitrite DataGate server. Setting up replication is very easy in Nitrite once a DataGate server instance is up and running.

We will discuss more on setting up a DataGate server in another article.

Further Reading

There is a lot more to it and I can not squeeze everything into a single article. We will discuss those things in coming days. In the meantime, if you feel interested head out to the Nitrite’s project page or GitHub repo. If you want to dig into Nitrite’s capabilities in more details, please go to its documentation page, where you will find all the tiny details with lots of examples.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade