Mongoose schema design

Quick start guide for Mongoose schema design.

1. New project

To create a new project, click the New item on toolbar and select Mongoose project type.

new mongoose project

2. Design schemata

To add a new schema to your Mongoose schema design, click the Schema item on toolbar and then click the diagram area.

new schema - toolbar

New object appears in the diagram. You can edit schema properties via Right Side panel:

Mongoose schema - properties editable via right side panel

If you prefer modal dialogs, double click an item on diagram or open popup and choose Edit:

editing mongoose schema

Properties

You can add new properties to a Mongoose schema in section Properties.
Specify new property name, datatype and click Add.

  • Param is a logical information only and doesn’t affect generated code.
  • NN stands for Not Null and indicates a required property.
  • ARR stands for Array.
mongoose schema - modal form

Property specifics

Property details can be defined in the expanded area.

mongoose schema and fields

3. Define hierarchies

In Mongoose structures you can easily define hierarchical structures.

A. Direct object properties

If you select Object as the data type, Moon Modeler will add to the diagram a new object represented by a separate box and automatically draw a containment line pointing to the contained object.

Select the new object and navigate to tab Properties and add new properties etc.

Specification of fields belonging to the contained object.

Generated script:

Generated Mongoose ODM script for the case when direct object properties are used.

B. Child schema

Another option is to create two schemas and then select the second schema as the data type for the main schema.

another child schema

C. Referenced schema

Alternatively, you can also create a reference between two schemas.

referenced schema

4. References in Mongoose schema design

References represent links between schemata. To create a new reference, click the Reference icon on toolbar and then click source schema and then target schema in your diagram. New property is added to target schema automatically.

Referenced schema

5. Code generation for Mongoose schema design

To preview script generated for selected object(s) click the Script tab on the object detail. And to generate scripts for the whole project and save the output to files, click the Script icon on the main toolbar.

Then click the Save output button.

We wish you a pleasant work and simple creation of your Mongoose Schema Design.

For more information about Mongoose, visit https://mongoosejs.com/

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