uuid-mongodb (v2.6.0) generates and parses BSON UUIDs for MongoDB, providing better performance than string UUIDs. It supports UUID v1 and v4, offers canonical and relaxed JSON serialization modes, and plays nicely with the native MongoDB driver and Mongoose. TypeScript types are included. The library uses the `uuid` package internally and focuses on binary UUIDs (SUBTYPE_UUID) for efficient storage and querying. Release cadence is irregular. Key differentiators: simple API, mode switching for JSON output, and direct integration with MongoDB's Binary type.
npm install uuid-mongodbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to MongoDB, inserts a binary UUID document, retrieves it, and prints the UUID string.
Always ensure Binary is of SUBTYPE_UUID (0x04). Use `MUUID.from(binary)` only for Binary with subtype UUID.
Avoid changing mode after initialization, or use a single consistent mode throughout the app.
Consider using `v4()` for non-predictable UUIDs if privacy is a concern.
Use `import MUUID from 'uuid-mongodb'` (default import) instead of `import { from } from 'uuid-mongodb'`.Run `npm install uuid` to install the missing dependency.
Use `new Binary(buffer, Binary.SUBTYPE_UUID)` before passing to `MUUID.from()`.
Ensure Mongoose schema field type is set to 'object' with value: { type: 'Buffer' } as shown in the documentation.