
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
MelonFire implements the WatermelonDB sync protocol via RNFirebase's React Native integration with Firestore. By integrating MelonFire, you can easily back up your WatermelonDB database with your Firestore instance in the cloud without writing any code yourself.
npm install melon-fire
or
yarn add melon-fire
import firestore from "@react-native-firebase/firestore";
import { Database } from "@nozbe/watermelondb";
import { syncMelonFire } from "melon-fire";
async function onSyncButtonPushOrRandomTimer(
db: Database,
userId: string,
) {
const syncDocRef = firestore()
.collection("users")
.doc(userId);
return await syncMelonFire(db, syncDocRef);
}
We now use a named export for syncMelonFire, which was needed because microbundle doesn't support having both a default export and a named export. So you'll now need to import { syncMelonFire } from "melon-fire" instead.
userId doesn't have to literally be a user id. It can be any valid Firestore
doc ID that you want associated with the backup/sync in Firestore. Similarly,
your collection doesn't have to be "users" — it can be anything you want.DocumentReference to MelonFire, which will then write several of
its own fields into the document (currently: melonLatestRevision,
melonLatestDate, and melonBatchTokens). It'll also create
a collection under syncDocRef for each table in your database, as well as a
collection called melonDeletes where it stores deletions. If you don't
mind these fields and collections living in a shared doc with other things
(e.g. if you want MelonFire's data to be kept in your user's profile doc),
it's fine; MelonFire won't overwrite your other fields/collections.syncMelonFire will throw if there are sync errors. Note that, in accordance
with WatermelonDB's guidance, syncMelonFire will actually catch the first
error it receives and retry sync one time on its own. This, for instance,
automatically resolves the most common sync issue, which is that another
writer has updated the cloud records since you last pulled changes. But in
cases where the first retry fails, syncMelonFire will throw.syncMelonFire
could take a while (especially if, say, you're pulling or pushing a ton of
changes). You don't necessarily have to await syncMelonFire if you're sure
your app can move on and do other things while sync is processing in the
background, but that might be a bad idea for most apps because you don't want
to be modifying the database even while sync is running (since your new
changes might conflict with what it pulls down from the cloud). But this is
ultimately up to your judgment — you know your app best.The WatermelonDB sync protocol is actually non-trivial to implement, especially if you'd like to sync your DB into Firestore. For example:
firestore().blah.set(),
firestore().blah.update(), and firestore().blah.delete() incorrect.MelonFire is a client-side library that relies on RNFirebase's Firestore integration. This means you won't need to push or maintain cloud functions, but can instead just integrate MelonFire into your app for easy DB sync or backup into Firestore. MelonFire overcomes the challenges listed above by:
Though MelonFire's architecture allows it to maintain consistency despite Firestore's 500-write limit, note that a consequence is that large batch writes are stored in Firestore without merging with past or future records. At the extreme, if your app only ever pushes huge batches (e.g. you modify the same 10k records every day, and then want to sync with the cloud daily), you'll be storing a copy of those records for each sync. Whereas if you only ever pushed less than 500 records at a time, MelonFire would never have more than one doc in Firestore for any one row in your database. If someone has a clever (and functionally correct) alternative to this implementation, please let me know.
schemaVersion and migrations from WatermelonDB's sync protocol aren't
supported yet. This isn't a technical limitation — it's merely because I don't
myself need these yet. If you have a need to process migrations, please submit
a PR and I'll be happy to integrate your work. Or I'll get to it when I need
it. If you use MelonFire in the meantime, just realize this means that
migrations won't work (i.e. if you start changing your schema, this library
won't maintain consistent data for you).FAQs
WatermelonDB Firestore sync
The npm package melon-fire receives a total of 28 weekly downloads. As such, melon-fire popularity was classified as not popular.
We found that melon-fire demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.