1.0.5 • Published 1 year ago

mongo-oid v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago