Socket
Socket
Sign inDemoInstall

mongo-oid

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-oid

A package to generate 12 bytes Hex String for MongoDB Object Id


Version published
Maintainers
1
Created
Source

mongo-oid

NPM licenseinstall sizenpm bundle sizenpm downloads

A package to generate 12 bytes Hex String for MongoDB Object Id

Updates:

  • Typescript Support Added

Install

npm install mongo-oid

or

yarn add mongo-oid

Usage

Just import oid() function from 'mongo-oid'

Below is the Example use case for upserting Data. (Update if id exists or create with the following Object Id)

import { oid } from "mongo-oid";

function From({ user }: { user?: UserType }) {
  const [doc, setDoc] = useState<{
    id: string;
    name: string;
  }>({
    id: user ? user.id : oid(),
    name: user ? user.name : "",
  });

  console.log(oid());
  // "f2a1b3c4d5e6a7b8c9d0e1f2"

  return <button onClick={Upsert}>Update Or Create</button>;
}

export default Form;

Contribution

Contributing on this project is always welcome! Just fork, update, push to your respective branch and make a pull request after testing. Make sure to open an issue before contribute.

License

MIT © Abdur Rahman

Keywords

FAQs

Package last updated on 04 Jun 2024

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc