Import MongoDB ODM Project


This short tutorial demonstrates that in Skipper import of existing MongoDB ODM project and the following model editing is simple and intuitive.

Hint: See the ODM Model basics for detailed description of ODM elements (e.g. bundle, entity).

Import project

First, import sample MongoDB ODM project Bug Tracker or some of your existing projects. To do this select Import ODM Schema Files from File menu and follow the steps shown in the pictures below.

Select Import ODM Schema Files
Select MongoDB ODM in Skipper schema definition import wizard
Select Symfony framework in Skipper schema definition import wizard

Enter directory to import in Skipper schema definition import wizard
Confirm files to import in Skipper schema definition import wizard
Wait for MongoDB ODM project import

Imported MongoDB ODM project summary screen
Diagram of imported MongoDB ODM Bug Tracker project
Generated diagram of imported MongoDB ODM Bug Tracker model

The last screen visually represents Bug Tracker project imported to Skipper and arranged automatically by import algorithm. It is a good starting point to work with your model.

Arrange visual model

Although imported model is automatically arranged it is a good idea to reposition entities inside the bundles to exactly fit the model logic. Also, you can change colors of bundles according to your preferences.

Rearranging automatically generated MongoDB ODM visual model
Arranged MongoDB ODM Bug Tracker model

Extend project model

Now that you have a nice visual model we are going to show you how to extend Bug Tracker model to store attachments for Bug reports. We add Attachment entity, configure new fields and create association between Bug and Attachment entity.

Select entity tool
Configure new MongoDB ODM entity in Skipper visual model
New MongoDB ODM entity created in Skipper visual model

Create new MongoDB ODM association in Skipper visual model
New MongoDB ODM association wizard in Skipper
New MongoDB ODM association created in Skipper visual model

Export model

Now with updated model it is time to export model back to MongoDB ODM schema definition files. Because model is imported from the existing schema files, export is automatically configured to export the data back to these files. Before the first export check that export locations and fODMats are correct.

Skipper exports single schema file for each MongoDB ODM entity. This means that our project will export five schema definition files, one for each entity in the model. Each bundle can have its own export fODMat and path which is relative to project root directory. For MongoDB ODM it is XML, YML and annotations.

Edit MongoDB ODM module settings
Configure MongoDB ODM schema definition files export settings
Click Export to ODM icon to generate MongoDB ODM schema definition files
MongoDB ODM schema definitions export settings window
MongoDB ODM schema definition files export results
Exported MongoDB ODM XML file

And here is an example of the new Attachment entity. As you can see, everything is well formatted and exported in MongoDB ODM XML format.

<doctrine-mongo-mapping ...>
	<document name="Entities\Attachment">
    		<field name="id" id="true" type="int"/>
    		<field name="caption" type="string"/>
    		<field name="description" type="string"/>
    		<field name="content" type="string"/>
    		<field name="bug_id" type="int"/>
    		<reference-one field="bug" target-document="Entities\Bug" inversed-by="attachment"/>
  	</document>
</doctrine-mongo-mapping>

Skipper can export schema definitions to all supported MongoDB ODM export formats - XML, YML or annotations. When you select annotations format export will look like this:

<?php
namespace Entities;
use Doctrine\ODM\MongoDB\Mapping\Annotations AS ODM;

/**
 * @ODM\Document
 */
class Attachment
{
    /**
     * @ODM\Id(type="int")
     */
    private $id;

    /**
     * @ODM\Field(type="string")
     */
    private $caption;

    /**
     * @ODM\Field(type="string")
     */
    private $description;

    /**
     * @ODM\Field(type="string")
     */
    private $content;

    /**
     * @ODM\Field(type="int")
     */
    private $bug_id;

    /**
     * @ODM\ReferenceOne(targetDocument="Entities\Bug", inversedBy="attachment")
     */
    private $bug;
}

Next time you will need to make further changes or adjust the model, just open Skipper file and edit your project entities. Then again export the project to ORM.

Conclusion

As you can see above, import, editing and export to schema definition files is a five minute work with Skipper (ten if you are doing it for the first time). Now compare it with the effort of doing such task manually. As you have just discovered Skipper dramatically saves your time and helps you to work with schema definitions in much more enjoyable way.

Video tutorials

Import new project

Export project


Import to project