AnchorDB
MongoDB + Mongoose for Mobile Apps · Offline-First Local Database
A local, persistent document database with a Mongoose-identical API that works completely offline on React Native, Expo, Ionic and the browser — and optionally syncs with a backend. Same Schema, same queries, same aggregation pipelines, no server required.
That Is Mongoose Code
A developer who knows MongoDB and Mongoose on the backend already knows AnchorDB — same Schema, same model(), same query builder, populate and aggregation.
The snippet runs offline, on a phone, with no server anywhere. Anything Mongoose does that AnchorDB cannot is written down explicitly, never silently reinterpreted.
Sync is optional. With no sync block there is no queue and no network code. Point it at an endpoint later and the CRUD code stays the same.
import { AnchorDB, Schema } from "anchordb";
const db = new AnchorDB({ name: "my-app" }); // no backend needed
const User = db.model("User", new Schema({
name: { type: String, required: true },
email: { type: String, required: true, unique: true, lowercase: true },
age: { type: Number, min: 0 },
}, { timestamps: true }));
await User.create({ name: "Nisala", email: "n@example.lk", age: 28 });
const adults = await User.find({ age: { $gte: 18 } })
.sort("-createdAt")
.limit(10);The Packages
Only anchordb is required. The rest are split out so an offline-only app never downloads Express, and an Express server never downloads React.
Phone · Browser · Node
The database — Schema, models, a lazy query builder, populate, aggregation, indexes, import/export and optional sync. The only package you need.
React Native · Expo
Live hooks — useFind, useFindOne, useCount, useAggregate, useSyncStatus — that re-render when data changes, with Expo SQLite storage ready after one install.
Angular · Ionic · Capacitor
DI providers and RxJS observables shaped like @nestjs/mongoose — SQLite on a device, IndexedDB in the browser.
Your backend
The server half of sync — an Express router, a NestJS provider and Next.js App Router handlers over MemoryStore or MongooseStore.
Your laptop · dev only
The anchor-relay CLI — connects a running app to the Anchor Lens inspector, with an optional bridge for moving collections to and from a real MongoDB.
QA builds · Android
Opens a QA build's database in Anchor Lens on the same Android phone, from a file — no laptop, no relay — and keeps both apps running in the background while they are connected.
Features
Mongoose-identical API — Schema, model(), documents with save(), virtuals, hooks, populate and the same error shapes
Real 12-byte MongoDB ObjectIds generated on-device, cross-validated byte-for-byte against the official bson package
Unique indexes enforced inside the write transaction, reported as a real E11000 with keyPattern and keyValue
Streaming aggregation pipelines with index pushdown and an explain() that reports IXSCAN vs COLLSCAN
Two-way MongoDB interop — Extended JSON and CSV that mongoimport reads, and mongoexport output imports back
Optional sync on Hybrid Logical Clocks, with five conflict strategies and a crash-safe offline mutation queue
NestJS-style @Schema / @Prop decorators, so one class file is shared by a mobile app and a NestJS service
Offline-only apps are first-class — adding a backend later is a config change, not a rewrite
Runs On
Anchor Lens
Anchor Lens is the companion inspector — a MongoDB Compass-style app for your phone. It browses and edits an AnchorDB database running inside another app on the same device, and any MongoDB database you paste a connection string for.
Open a QA build's database from a file with anchordb-lens-link, or connect through anchordb-relay on the same Wi-Fi. Pairing is end-to-end between the app and Lens over an HMAC challenge, so a relay can never grant a session.
MongoDB goes through a stateless HTTPS bridge that stores nothing and refuses private network addresses. Connection strings stay in the phone's secure storage, and passwords never appear in an error.
Two tabs: Local for AnchorDB apps, and MongoDB for any cluster, Atlas included — paste a connection string and keep as many as you like
Collections open as tabs, each keeping its own filter, sort and page
Browse, edit, bulk-update and delete documents; create and drop databases, collections and indexes
Import and export JSON or CSV, an aggregation builder with explain, and an index inspector
Decimal128, Long and Date keep their types through an edit — documents stay Extended JSON end to end
Open an app on the same phone from its link file, with both apps kept running in the background
Sync queue and conflict viewer
Pairs over a QR code plus a separate pairing code — photographing the screen is not enough
About This Project
I built AnchorDB after shipping offline-first mobile apps for field users with unreliable connectivity, where the backend spoke MongoDB and Mongoose but the device needed a database of its own. The goal is zero re-learning: the models, queries and aggregation pipelines you write on the server should run unchanged on the phone — including real ObjectIds and a real E11000.
AnchorDB and Anchor Lens are solely designed, developed, and maintained by Nisala Nadeera Kudaligamage, and the packages are published on npm under knnadeera.
Bugs, Support & Feedback
Found a bug, stuck on setup, or missing a Mongoose feature you rely on? Send it here — it comes straight to me, and I reply by email.
A Useful Bug Report
The package and exact version — npm ls anchordb prints it
Where it runs — Expo, Ionic, browser or Node — and which storage adapter
The smallest snippet that reproduces it
The full error, including code, keyPattern and keyValue for an E11000
What you expected to happen instead
Sync Problems
Mention your conflict strategy and whether the mutation shows as parked in Anchor Lens — a rejected unique-index push parks rather than retrying forever.
Open-source npm packages by Nisala Nadeera Kudaligamage