You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

bson-objectid

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bson-objectid

Construct ObjectIDs without the mongodb driver or bson module

2.0.4
latest
Source
npmnpm
Version published
Weekly downloads
243K
-1.78%
Maintainers
3
Weekly downloads
 
Created

What is bson-objectid?

The bson-objectid npm package is a utility for generating and working with BSON ObjectIDs, which are commonly used as unique identifiers in MongoDB. This package allows you to create new ObjectIDs, convert them to strings, and parse them from strings.

What are bson-objectid's main functionalities?

Generate a new ObjectID

This feature allows you to generate a new BSON ObjectID. The generated ID is a 12-byte identifier that is unique and can be used as a primary key in MongoDB.

const ObjectId = require('bson-objectid');
const id = new ObjectId();
console.log(id.toString());

Convert ObjectID to string

This feature allows you to convert a BSON ObjectID to its string representation. This is useful for storing or transmitting the ID as a string.

const ObjectId = require('bson-objectid');
const id = new ObjectId();
const idString = id.toString();
console.log(idString);

Parse ObjectID from string

This feature allows you to parse a string representation of an ObjectID back into a BSON ObjectID. This is useful for converting IDs received as strings back into their original ObjectID format.

const ObjectId = require('bson-objectid');
const idString = '507f1f77bcf86cd799439011';
const id = ObjectId(idString);
console.log(id);

Other packages similar to bson-objectid

Keywords

ObjectID

FAQs

Package last updated on 21 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.