Skip to content

Data Generator

  • MongoDB

The Data Generator fills a collection with made-up documents for tests and demos: names, addresses, numbers, dates and more, shaped like the collection’s own documents. Each field has a rule that says what it holds, and a seed makes the same documents again.

  • Choose Generate Data… from a collection’s menu in the explorer.
  • Run MongoDB: Data Generator… from the command palette.

The panel starts with a rule per field of a sample of the collection, nested fields included. Each rule follows the field’s most common type and its name: a field named email gets email addresses, city gets cities, and an Int32 field gets numbers in the range the sample saw. A string field with ten values or fewer picks among them. Arrays get the kind of their elements and the lengths the sample saw, and a field missing from part of the sample is missing from the same share of documents. An empty collection starts with an id, a name and an email address.

  1. Check each rule: the Field (a dotted path such as address.city), its Value and its Settings.
  2. Under Missing, set the percentage of documents that leave the field out.
  3. Under Array, leave it empty for one value, or enter n or n-m for an array of that many values.
  4. Add field adds a rule, and the close button at the end of a row removes one. Read fields again starts again from a new sample.
  5. Choose Preview to see The first documents a run makes.
Value Settings
ObjectId, UUID None
Sequence Where it starts and the step
First name, Last name, Full name, Email address, Phone number, Company, Street address, City, Country, Postal code, Web address None
Words, Sentence The fewest and the most words
Int32 in a range, Int64 in a range From and to
Double in a range, Decimal128 in a range From, to and the number of decimals
Boolean The percentage of true values
Date in a range From and to dates, such as 2020-01-01
One of a list The values in mongosh syntax, such as ['A', 'B', 'C']
Constant The value in mongosh syntax
Null None

Email and web addresses use the reserved example.com, example.net and example.org domains, and phone numbers the 555 exchange, so no generated address reaches a real person.

Querybara checks the rules before it makes anything and names the field of a rule that cannot work: a range that starts above its end, a list that does not parse, two rules for one field, or a field inside another rule’s value.

  1. Set Documents to how many to make, up to 1,000,000.
  2. Keep the Seed, or choose the button beside it for a new one. The same seed and rules make the same documents, and the preview shows exactly the documents a run starts with.
  3. Pick whether the documents are added to the collection or are replacing what it holds.
  4. Choose Generate. The confirmation shows the commands; choose Generate, or Delete and generate when the new documents replace the old ones.

The documents go in batches of 500, and the panel counts them as they go. Stop ends the run after the batch in flight. A schema validator on the collection applies as to any insert, and a read-only connection does not generate.

The rules are not saved: they last while the panel is open.

Documents Querybara 0.1.19 · built from89dc752