https://github.com/prolincur/bsonid
Generates unique id which are friendilier with mongodb
https://github.com/prolincur/bsonid
Last synced: 2 months ago
JSON representation
Generates unique id which are friendilier with mongodb
- Host: GitHub
- URL: https://github.com/prolincur/bsonid
- Owner: prolincur
- License: mit
- Created: 2024-04-16T23:13:45.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-07T06:02:15.000Z (9 months ago)
- Last Synced: 2025-04-02T17:49:06.263Z (3 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/bsonid
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bsonid
An utility on browser and node to create MonogoDB friendly object id based on current system time.
[ObjectIds](https://www.mongodb.com/docs/manual/reference/bson-types/#objectid) 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](https://www.npmjs.com/package/uuid)
Of course, you can use [uuid](https://www.npmjs.com/package/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
```javascript
import { bsonId } from 'bsonid'const id = bsonId()
console.log(id)```
### Author
[Prolincur Technologies](https://prolincur.com)