Generating fake data for mongoose 'ref' attributes #2287
-
Clear and concise description of the problemI'm trying to fake data for this schema, however this schema also references various other schemas. How can I do that ?
Suggested solutionIs there a way we could have this feature ? or is there a workaround?
AlternativeNo response Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You are already on the right path, but should have a look into our docs https://fakerjs.dev/guide/usage.html#create-complex-objects Also I can recommend to use |
Beta Was this translation helpful? Give feedback.
-
You could use helpers.arrayElement instead. If you wish to generate "valid" references, then I would recommend generating a list of therapists and using helpers.arrayElement to select one of them before picking its id and referencing it elsewhere. |
Beta Was this translation helpful? Give feedback.
You are already on the right path, but should have a look into our docs https://fakerjs.dev/guide/usage.html#create-complex-objects
Also I can recommend to use
let tags = faker.helpers.arrayElement(tag);
, because that way you rely on Faker's seed value and get deterministic results.