Generating MongoDB Schema Validation Scripts

To generate a MongoDB schema validation scrip from your Moon Modeler project, click the Script icon on the main toolbar.

Script Preview

A preview of the MongoDB schema creation script will appear in the Script modal form. On the form, you can also preview output generated by several predefined templates, such as schema modification script, export to CSV and other templates.

Moon Modeler and template selection for generating schema validation or modification script for MongoDB

Click the Save output button and select a location to save the files. The Overwrite existing files option allows you to ignore existing scripts and overwrite them without displaying a warning. For more information about MongoDB schema validation, see MongoDB manual

Templates Toolbar

On the Script and Templates tab you will find a toolbar with a diagram selection, a template selection and also the following buttons:

  • Syntax highlighting – especially useful for javascript or json code
  • Beautify
  • Show HTML code – for output that is in HTML format
  • Open folder with templates
  • Reload templates – if you add a custom template
  • Documentation – link to documentation
Output that shows commands for index creation for MongoDB collections.

Collapsible Sections and Easy Copying

In terms of a user-friendly interface, you have the option to collapse or expand the generated script for individual objects and to copy the script for selected object into the clipboard easily.

Moon Modeler and custom template for generating indexes for MongoDB collections.

Modal Forms & Custom Template Based Scripts

The generated script for the selected object(s) can be viewed also on the object Details modal form. Navigate to the Script tab where you will find everything you need, including:

  • Generation settings
  • Before and after scripts
  • Custom code
  • Script and Templates with custom template based output.

The combination of all options and possibilities provides exceptional flexibility.

A form with selected object details and generated script for MongoDB

Side Panel & Template Based Output

In your templates you can write a code that will be generated only for the currently selected object and e.g. dependent objects. Thus, it is not necessary to generate the output for the whole project and then search for the file with the generated code. Just select a collection, reference or other object in the diagram and view your own template based script output in the sidebar.

Side panel with generated mongodb schema validation script

Templates Structure

When you open the templates folder, you will see a simple structure. To create a custom template, just create one simple json file describing the template and one hbs file containing the template written in Handlebars. You then only need to write a few lines of code to output a list of findOne statements for your collections. Writing templates is easy and based on a well-known templating system. There is no need to reinvent the wheel!

Comfortable Templates Development

In rare cases, you may make a mistake when creating a template. In this case, the Handlebars templating system will display an error instead of the generated content. This way you can immediately see where to look and there is no need to restart Moon Modeler at all.

Our goal is to make your work comfortable and pleasant even if some modification of the templates is required.

Read more about templates

#

DATA MODELING TOOLS
DRAW Diagrams and
GENERATE Scripts
Download data modeling tools
Blog Categories
Blog by Platforms