mongo-oid
v1.0.5
Published
A package to generate 12 bytes Hex String for MongoDB Object Id
Downloads
115
Maintainers
Readme
mongo-oid
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