{"id":43742,"library":"react-native-local-mongodb","title":"React Native Local MongoDB","description":"A lightweight embedded persistent or in-memory database for React Native, providing a subset of MongoDB's API (NeDB-compatible). Current stable version is 4.0.0. It uses AsyncStorage for persistence on React Native. Key differentiators: no native dependencies, TypeScript types included, supports indexing, serialization hooks, and timestamp data. Compared to alternatives like WatermelonDB or Realm, it is simpler and ideal for small offline-first apps. The library switched from promise-based methods to callback-style in v2.0.0, adding Async methods.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/antoniopresto/react-native-local-mongodb","tags":["javascript","database","datastore","embedded","react-native","mongodb","typescript"],"install":[{"cmd":"npm install react-native-local-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add react-native-local-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add react-native-local-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency for React Native environment.","package":"react-native","optional":false}],"imports":[{"note":"Default export is Datastore, which is a class. The 'async' suffix methods (e.g., insertAsync) are available since v2. Common mistake: using require() but package is ESM-friendly with TypeScript types.","wrong":"const Datastore = require('react-native-local-mongodb');","symbol":"Datastore","correct":"import { Datastore } from 'react-native-local-mongodb';"},{"note":"For CommonJS usage, destructure from the module. Do not access .Datastore property incorrectly.","wrong":"const Datastore = require('react-native-local-mongodb').Datastore;","symbol":"Datastore","correct":"const { Datastore } = require('react-native-local-mongodb');"},{"note":"TypeScript users: import the type if only need type information, but the library ships types so no separate type package needed.","wrong":null,"symbol":null,"correct":"import type { Datastore } from 'react-native-local-mongodb';"}],"quickstart":{"code":"import { Datastore } from 'react-native-local-mongodb';\n\n// Create a database collection (persistent)\nconst db = new Datastore({\n  filename: 'mycollection',\n  autoload: true\n});\n\n// Insert a document using callback (pre-Async style)\ndb.insert({ hello: 'world', count: 1 }, (err, newDoc) => {\n  if (err) console.error(err);\n  else console.log('Inserted:', newDoc);\n});\n\n// Or use insertAsync (promise-based)\ndb.insertAsync({ hello: 'world', count: 2 })\n  .then(doc => console.log('Async inserted:', doc))\n  .catch(err => console.error(err));\n\n// Find documents\ndb.find({ hello: 'world' }, (err, docs) => {\n  console.log('Found:', docs);\n});\n\n// Find with sort and limit\ndb.find({}).sort({ count: -1 }).limit(2).exec((err, docs) => {\n  console.log('Top two:', docs);\n});\n","lang":"typescript","description":"Create a persistent Datastore, insert a document using both callback and Async methods, and perform a simple find with sorting."},"warnings":[{"fix":"Use callback syntax or switch to Async methods (e.g., insertAsync) for promises.","message":"In v2.0.0, insert, update, remove, find, and findOne no longer return promises. Use the Async suffix methods (insertAsync, etc.) for promise support.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"If you need persistence, set inMemoryOnly to false and provide a filename.","message":"The in-memory only mode is still supported but the filename option is ignored in that case. Ensure you don't rely on persistence when inMemoryOnly is true.","severity":"deprecated","affected_versions":"*"},{"fix":"Consider using a more robust solution like WatermelonDB if data durability is critical.","message":"Persistence uses AsyncStorage keys that may be cleared by the user or during app updates. Data is not guaranteed to survive across reinstalls.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure your hooks are exact inverses and test with various string lengths.","message":"AfterSerialization and beforeDeserialization hooks must be inverses; the library checks randomly but misuse can cause data loss.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'4.0.0':31 'ad':87 'altern':57 'api':23 'app':72 'async':88 'asyncstorag':34 'base':79 'callback':83 'callback-styl':82 'compar':55 'compat':26 'current':27 'data':54 'databas':13,91 'datastor':92 'depend':44 'differenti':41 'embed':7,93 'first':71 'hook':51 'ideal':66 'in-memori':10 'includ':47 'index':49 'javascript':90 'key':40 'librari':74 'lightweight':6 'like':58 'local':3 'memori':12 'method':80,89 'mongodb':4,21,97 'nativ':2,16,39,43,96 'nedb':25 'nedb-compat':24 'offlin':70 'offline-first':69 'persist':8,36 'promis':78 'promise-bas':77 'provid':17 'react':1,15,38,95 'react-nat':94 'realm':61 'serial':50 'simpler':64 'small':68 'stabl':28 'style':84 'subset':19 'support':48 'switch':75 'timestamp':53 'type':46 'typescript':45,98 'use':33 'v2.0.0':86 'version':29 'watermelondb':59","created_at":"2026-06-05T17:01:15.529442+00:00","updated_at":"2026-06-05T17:01:15.529442+00:00","problems":[{"fix":"Use autoload: true or load the database via loadDatabase callback before performing operations.","cause":"Trying to use db.insert before the Datastore is fully loaded (async).","error":"Cannot read property 'insert' of undefined"},{"fix":"Update to v2.0.0+ or use callback-based insert.","cause":"Using an older version (<2.0.0) where Async methods didn't exist.","error":"db.insertAsync is not a function"},{"fix":"If you want in-memory, omit filename. If you want persistence, set inMemoryOnly: false.","cause":"Passing both filename and inMemoryOnly: true is not allowed.","error":"You can't use inMemoryOnly mode with a filename"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/antoniopresto/react-native-local-mongodb","github":"ssh://git@github.com/antoniopresto/react-native-local-mongodb","docs":null,"changelog":null,"pypi":null,"npm":"react-native-local-mongodb","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}