Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Generate MongoDB ObjectId #45

Open
ccornici opened this issue Jul 25, 2022 · 1 comment
Open

[Feature Request] Generate MongoDB ObjectId #45

ccornici opened this issue Jul 25, 2022 · 1 comment

Comments

@ccornici
Copy link

Hello maintainers, given how popular of a DB Mongo is I think many people would appreciate having an ObjectId generator. What do you think?

@webroo
Copy link
Owner

webroo commented Aug 20, 2022

Thanks, I like this idea, I'll be sure to add it in a future update. Will keep this open until I do.

I know an ObjectId isn't just a random hex string but here's a custom helper I threw together in the meantime.

const myHelpers = {
  objectid() {
    return 'xxxxxxxxxxxxxxxxxxxxxxxx'.replaceAll(
      'x',
      () => dummyjson.utils.randomInt(0, 0xf).toString(16)
    );
  }
};

const template = '{{objectid}}';
const result = dummyjson.parse(template, { helpers: myHelpers });
console.log(result); // 35bebbc8b80d567fbafb6c16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants