Registry / database / short-mongo-id

short-mongo-id

JSON →
library0.1.1jsnpmunverified

Generates short, URL-safe IDs from MongoDB ObjectIds using timestamp and counter components. Version 0.1.1 is a legacy package with no recent updates. Unlike base64 encoding, it produces compact alphanumeric strings but is one-way and should not be used for security or high-uniqueness requirements. Lightweight with zero dependencies.

npm install short-mongo-id
INSTALL
IMPORT
SIG · SHORT-MONGO-ID
S
short-mongo-id
databasejavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (function)
import shortId from 'short-mongo-id'
import { shortId } from 'short-mongo-id'
The package exports a default function. Named import will result in undefined.
default (require)
const shortId = require('short-mongo-id')
const { default: shortId } = require('short-mongo-id')
CommonJS require works directly; no destructuring needed.
type import
import type { ShortMongoId } from 'short-mongo-id'
import shortId from 'short-mongo-id' // for types
TypeScript definitions are not included; you may need to declare types manually.

Converts a MongoDB ObjectId string into a short alphanumeric ID. Works with any valid ObjectId.

import shortId from 'short-mongo-id'; const mongoId = '507f191e810c19729de860ea'; const short = shortId(mongoId); console.log(short); // e.g., 'iTxuMF'
Debug
Known issues
gotchaThe short ID is not reversible; original ObjectId cannot be recovered.
fix
If you need to reverse, store the mapping separately.
affects: >=0.0.0
deprecatedPackage is no longer maintained; no updates since 2014.
fix
Consider using nanoid or uuid with a custom transformation for modern needs.
affects: >=0.0.0
gotchaCollisions are possible, though unlikely; uniqueness is not guaranteed.
fix
Do not rely on this for primary keys or security tokens.
affects: >=0.0.0
gotchaRequires a valid MongoDB ObjectId string; non-conforming strings throw an error.
fix
Validate ObjectId before passing: use /^[a-f\d]{24}$/i.test(id).
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: shortId is not a function
Using named import instead of default import.
fix
Use `import shortId from 'short-mongo-id'` or `const shortId = require('short-mongo-id')`.
Error: Argument must be a valid Mongo ObjectId
Passing an invalid format (non-hex, wrong length) to shortId.
fix
Ensure the input is a 24-character hex string representing a MongoDB ObjectId.
Cannot find module 'short-mongo-id'
Package not installed or not in node_modules.
fix
Run `npm install short-mongo-id`.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Meta
1
Resources
short-mongo-id — npm install short-mongo-id · libregistry