low-json-db

ID Generation

low-json-db can automatically generate unique IDs for your documents. You control the behavior through collection options.

Options

const users = db.collection({
  name: 'users',
  autoId: true,          // default is false
  idField: '_id',        // default
  idType: 'auto'         // 'auto' | 'uuid' | 'objectid'
});

ID Types

TypeDescriptionExample
autoSimple auto-increment integer1, 2, 3, ...
uuidUUID v4 (via crypto.randomUUID)a1b2c3d4-...
objectidObjectId-style (timestamp + random)66c3a1b2f8e9...

rebuildId()

After importing data or manually editing documents you can recalculate the next auto-increment value:

users.rebuildId();
await users.rebuildIdAsync();
Next: Learn about Import & Backup.