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
| Type | Description | Example |
|---|---|---|
auto | Simple auto-increment integer | 1, 2, 3, ... |
uuid | UUID v4 (via crypto.randomUUID) | a1b2c3d4-... |
objectid | ObjectId-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.