Quick Start Guide & Tips and Tricks
MongoDB Schema Design
Quick start guide for MongoDB schema design in Moon Modeler.
- New project
- MongoDB schema design - collections
- MongoDB schema design - documents
- Embedded documents vs References
- Code generation
1. New Project
To create a new project, click the New item on toolbar and select MongoDB project type.
2. Design collections
To add new MongoDB collection to your design, click the Collection item on toolbar and then click the main diagram area.
New object appears in the diagram. You can edit MongoDB collection properties via Right Side panel:
If you prefer modal dialogs, double click an item on diagram or open popup and choose Edit:
In section Details collection settings can be specified. For example: caped collection, validation level etc.
In section Fields you can add new fields to collections to your MongoDB schema design. Specify new field name, datatype and click Add.
ARR indicates Array.
NN represents required field. (not null)
To access area where MongoDB field specifics can be modified, click the arrow left to the field name.
3. Design documents
MongoDB documents are objects that can be embedded to collections or other documents.
Example: See collection customer. Field contact contains embedded document contact. And this document contains two fields: addresses and phones. Both the fields are arrays and contain embedded documents address and phone.
To create new document, click the Document icon on toolbar and then click the main area.
Embedding documents to collections
To embed the document to a collection, edit the target collection and select document name from Datatype selectbox.
Collections vs Documents in MongoDB design process
During your design process you might consider changing document to collection or vice versa. In order to avoid manual redefinition, enable or disable the Document switch in properties. This switch allows you to change document to collection and let the tool generate MongoDB validation script for the collection.
4. References in MongoDB schema design
References represent links between collections. In the following example, collection article contains reference to collection vendor. In the article collection only ID is stored. Compare it with the vendor collection where field address contains embedded document address. Such field contains full data, incl. street, city, zip and country values.
5. Code generation
To preview validation script for your MongoDB schema design, click the Script tab on collection detail.
To save scripts to files, click the Script icon on toolbar and then click Save script.
This is the end of the MongoDB schema design page. Thanks for reading!