ObjectId as an option for test data generator

Anton Sorokin shared this idea 4 years ago
Under Consideration

Would be nice to have an option to generate ObjectID field in test data generator dialog. Ideally I want to have an option to randomly spread all the generated objects between preselected set of IDs or between IDs from the other collection.

Simple use case - I want to generate 10K documents with userId property and assign those document userIds to lets say random userId from users collection.

Replies (1)


The following code may be a little help.

const userIds=db.users.select("_id").limit(1000*10).map(it=>it._id);

sampleDoc.userId=  _.sample(userIds); // will return one item randomly from the  userIds array

Leave a Comment
Attach a file