'How to generate test data for mongodb in bulk which has reference to different collections?

I'm working on a Node.JS project with Mongodb as a database. I want to test how the api performs when the db collection has thousands of documents in it.

So I'm trying to fill the collection with test data but the problem here is, I've multiple associations for a single collections, i.e multiple reference fields in collection.

So is there any api available which allows me to generate data that supports reference fields too.



Solution 1:[1]

There is an old library for creating dummy data in mongoose: mongoose-dummy. But it doesn't look like it handles referenced documents.

You can also use faker to create eg. addresses, emails, names, numbers etc.

This is one of those things you really need to DIY (though you can use the above libraries to make it easier)

You created your application and models. Only you will be able to make realistic test data. For example, you will need to decide how many documents to create for a comment model on a blog post model based on what either historical data or your expectations if none exists.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 caffeinated.tech