dummy-json icon indicating copy to clipboard operation
dummy-json copied to clipboard

[Feature Request] Generate MongoDB ObjectId

Open ccornici opened this issue 2 years ago • 1 comments

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

ccornici avatar Jul 25 '22 16:07 ccornici

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

webroo avatar Aug 20 '22 08:08 webroo