{"library":"minimongo","title":"Minimongo","description":"Minimongo is a client-side, in-memory MongoDB clone designed for browser and Node.js environments, offering a MongoDB-like API for CRUD operations and query syntax. It supports various local storage backends including IndexedDB, WebSQL (legacy), LocalStorage, and a purely in-memory option, with an autoselection utility. Currently at version 7.1.1, the project aims for stable releases without a strict public cadence, evolving from a 2014 fork of Meteor.js's minimongo package to incorporate more geospatial queries and npm-friendliness. Its key differentiators include hybrid local/remote synchronization with conflict resolution using base documents, replication between database instances, and support for Extended JSON (EJSON). While it offers a substantial subset of MongoDB query features, it does not support the full aggregation pipeline or all operators.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install minimongo"],"cli":null},"imports":["import { MemoryDb } from 'minimongo';","import { IndexedDb } from 'minimongo';","import { HybridDb } from 'minimongo';","import { utils } from 'minimongo';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { IndexedDb, HybridDb, RemoteDb, MemoryDb } from 'minimongo';\n\ninterface MyDocument {\n  _id?: string;\n  name: string;\n  age: number;\n  tags?: string[];\n}\n\nasync function setupDatabase() {\n  return new Promise<IndexedDb<MyDocument>>((resolve, reject) => {\n    const indexedDb = new IndexedDb<MyDocument>(\n      { namespace: 'myAppDb', autoCreate: true },\n      () => {\n        console.log('IndexedDb initialized successfully.');\n        resolve(indexedDb);\n      },\n      (error: Error) => {\n        console.error('IndexedDb initialization failed:', error);\n        reject(error);\n      }\n    );\n  });\n}\n\nasync function runApp() {\n  try {\n    const localDb = await setupDatabase();\n    const remoteDb = new RemoteDb('/api/collections', 'myAppDb', {\n      // For a real application, replace with a proper HTTP client\n      // This is a minimal mock for demonstration\n      httpClient: {\n        get: async (url: string) => {\n          console.log(`[RemoteDb] GET ${url}`);\n          if (url.includes('myAppDb/items')) {\n            return { status: 200, data: [{ _id: 'remote1', name: 'Remote Item', age: 30 }] };\n          }\n          return { status: 404, data: { message: 'Not Found' } };\n        },\n        put: async (url: string, data: any) => {\n          console.log(`[RemoteDb] PUT ${url}`, data);\n          return { status: 200, data: { ...data, _id: data._id || 'newRemoteId' } };\n        }\n      },\n      useQuickFind: true\n    });\n\n    const hybridDb = new HybridDb(localDb, remoteDb);\n    hybridDb.addCollection('items');\n    const itemsCollection = hybridDb.getCollection('items');\n\n    // Insert a document locally\n    const newItem: MyDocument = { name: 'Local Item', age: 25, tags: ['frontend'] };\n    await itemsCollection.upsert(newItem, null, (doc: MyDocument) => {\n      console.log('Inserted local item:', doc);\n    });\n\n    // Query local and remote (hybrid sync)\n    console.log('\\nQuerying all items (local and remote sync):');\n    itemsCollection.find({}).fetch((docs: MyDocument[]) => {\n      console.log('Found items:', docs);\n    });\n\n    // Demonstrate another local operation\n    const anotherItem: MyDocument = { name: 'Another Item', age: 40 };\n    await itemsCollection.upsert(anotherItem, null, (doc: MyDocument) => {\n      console.log('Inserted another local item:', doc);\n    });\n\n    // Query with selector\n    console.log('\\nQuerying items with age > 25:');\n    itemsCollection.find({ age: { $gt: 25 } }).fetch((docs: MyDocument[]) => {\n      console.log('Found items (age > 25):', docs);\n    });\n\n  } catch (error) {\n    console.error('Application failed:', error);\n  }\n}\n\nrunApp();\n","lang":"typescript","description":"This quickstart demonstrates initializing an IndexedDb locally, setting up a mock RemoteDb, creating a HybridDb for combined local/remote operations, and performing basic CRUD and queries with synchronization.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}