MongoDB JSON Generation

From ER/Studio Data Architect
Jump to: navigation, search

Go Up to Generating a Script File or Database

The DDL Generation Wizard lets you generate JSON code to build a MongoDB database.

Use the expanded Generation Options in the DDL Generation Wizard to support output and input JSON Instance and Schema files.

To generate a script file or database

  1. On the Data Model Explorer, right-click on a physical model, and then select Generate Database.
  2. Follow the steps in the DDL Generation Wizard to complete the process.

Page 1: Select Target for Output

ERDA DDL Wizard Mongo 1.png

Generate Script File

  • Generate a Single, Ordered Script File. If selected, it writes a single JSON file with specification of all objects.
    • Database Creation Script File. This control allows you to provide the filename and path for the generated JSON file.
  • Generate Objects To Multiple Files. If selected, it writes a separate JSON file for each selected object. Objects are ordered in subdirectories for each selected object class.
    • Base Directory. This control allows you to specify the directory that is to contain the generated script files.

Generate Objects with a Database Connection

This option is not available during JSON file creation.

Wizard Quick Launch

See how you can load DDL Generation Wizard settings from a file created on a previous session.

Page 2: Object and Generation Options

192 ERDA DDL Wizard Mongo JSON.png

Object Selection and Generation Options

The Generation Options are on the tabs where you select the objects in the data model for which you would like to build the JSON file. Below you can see the explanation of some specific objects.

Collections tab

Under the Collection tab you can select which collections from your model that you want to add to your JSON file.

Use the Generation Options to select how you want your JSON output to appear.

  • Output as JSON Instance must be selected to use the JSON Instance Options. Likewise, Output as JSON Schema must be selected to use the JSON Schema Options.
  • Quote field names selects whether you want to add quotation marks around field names.
    • Only quote field names containing... means that only field names containing a period are enclosed in quotation marks.
    • Quote all field names means that all field names in the generated JSON will be contained in quotation marks.
  • Output as plain JSON means to remove all MongoDB-specific constructs when generating a database for a MongoDB model. This option removes MongoDb constructs such as ObjectId() and instead a generic JSON is generated.
  • JSON Schema Version
  • Add objects to $def
    • All Nested Objects adds all nested objects under the $def keyword.
    • Only reused Nested Objects adds reused nested objects under the $def keyword. A reused nested object is one that is used in other parent objects.
  • Manage Reusable Definitions
    • Address relative to Root signifies that every object added to the $defs section is referenced by its name relative to the $defs object using $ref. For example, "$ref":"#/$defs/nestedObjectName"
    • Address relative to Base URI signifies that every object added to the $defs section is given an $id comprised of the Relative URI extension plus the object name. This is referenced by parent fields using $ref.
    • Roll up Nested Objects adds every object to the parent field, similar to the roll-up view.

Notepad blue icon 2.pngNote: In the JSON tab of the Object Editor, you can choose an option under Customize that generates the JSON as JSON Instance (default) or JSON Schema. The options mimic those in the Generation Wizard and follow all rules of the Customize feature. For more information about this feature, see Customizing the JSON Tab.

Magic Wand Icon.pngTips:

  • If you right-click anywhere on the object tree within the wizard, you can select or deselect all objects using the short-cut menu. You can also display or hide object owner names for those objects with owners.
  • To view the DDL generated by the currently selected settings, click the JSON Preview button on the wizard at anytime. You can print or save the script directly from the JSON Preview dialog.

JSON Preview File

ERDA DDL Wizard Mongo 4.png

Page 3: Summary

ERDA DDL Wizard Mongo 3.png

In this page you can check if you have selected all the objects you want to generate on the DDL and the options to do it.

Wizard Quick Launch Options

See how you can save the DDL Generation Wizard settings to a file. You can also rename or delete one you have already created.

See Also