bsonid

1.0.0 • Public • Published

bsonid

An utility on browser and node to create MonogoDB friendly object id.

ObjectIds in MongoDB are small, likely unique, fast to generate, and ordered. ObjectId values are 12 bytes in length, consisting of:

  • A 4-byte timestamp, representing the ObjectId's creation, measured in seconds since the Unix epoch.

  • A 5-byte random value generated once per process. This random value is unique to the machine and process.

  • A 3-byte incrementing counter, initialized to a random value.

Why not use uuid

Of course, you can use uuid. However, in the scenerio where you want to insert the object to MonogoDB; uuid would not be accepted by MongoDB. That's where, bsonId can be helpful to you.

Install

yarn add bsonid

Usage

import { bsonId } from 'bsonid'

const id = bsonId()
console.log(id)

Author

Prolincur Technologies

Package Sidebar

Install

npm i bsonid

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

6.13 kB

Total Files

4

Last publish

Collaborators

  • prolincur