MongoDB Data Modeling and Code Generation

Daprota improves software creation efficiency and software quality by providing free cloud services and presenting ideas for automatic software creation.

Java Code Generation MongoDB Schema Design

M2 Cloud Service

Try out our free M2 service for the creation and management of data models and Java code generation for a leading NoSQL database management system MongoDB.

Before you start creating your own MongoDB data models, first check out the basics of the MongoDB data model that M2 implements via Tara Modeling Ontology.

You can browse public and Daprota models without signing in.

Public models

Free Plan

The free M2 service plan enables creation and management of up to five private and unlimited number of public data models and an unlimited access to all public data models provided by Daprota and M2 service users. You can also generate Java code from your models. This is an extremely useful feature that will significantly save you time during the development and testing phase of your project.

Plan upgrades with either larger or unlimited number of private models and additional features will be available in the near future.

Sign in  Sign up

M2 Features

  • Management of models and their elements.
  • Automatic Java code generation. Both persistence API and test code are generated.
  • Copying and versioning of models and its elements.
  • Full models' view in a JSON-like format.
  • Export/Import Models
  • Public models sharing
  • Models documentation repository
  • Messaging between M2 users


Regardless of the dynamic polymorphic nature of the MongoDB data schema, it is a good software engineering practice to first design a data model for your MongoDB application before proceeding with the application code development. There are at least a few reasons to follow this design practice. They include but they are not limited to data consistency, application correctness and performance.

M2 service can also be very useful for a quick creation of disposable schemas (data models) in an agile environment where you want to quickly create data models, generate Java persistence code from it, immediately test it, and repeat this procedure starting over with the current schema update or a completely new schema creation and code generation.

Besides supporting software engineering practices and automatic code generation, Daprota M2 service is also free of charge. We have spent our time and resources investing in Daprota's future by helping you achieve your goals where success is measured not only by the time and resources you spent on your projects but also by the quality and efficiency of your solutions based on Daprota's services.

Getting Started

First, you will think about your data and application read/write patterns. This thinking will help you create a model in M2 that will work for you. You can consult the Daprota MongoDB Modeling Adviser to help you with your data model design and its creation via M2 service.

Second, when you create the first version of your model you will generate code from it. Currently plain Java code is supported. Besides the data persistence code, the code based on the NoSQLUnit to test the generated data persistence code is also generated.

Third, you will run tests based on generated NoSQLUnit-based code to make sure that the persistence code generated by M2 and based on your model works properly.

You will definitely have to go through few iterations before the good model version is finalized and code generated based on it. M2 will save you a lot of time since many time consuming manual steps will be automatically done by M2.