#mongodb #mango #mongo #model #macro

macro metamorphose

Macros collection for converting Structure to Model, for a green-barrel project

2 stable releases

Uses new Rust 2021

1.3.4-beta Dec 15, 2022
1.2.1-beta Nov 27, 2022
0.7.16 Aug 6, 2022
0.7.8 Jul 26, 2022
0.2.2-alpha.2 Nov 21, 2020

#130 in Procedural macros

27 downloads per month
Used in mango-panel


537 lines



Macros collection for converting Structure to Model, for a Green Barrel project.

crates.io crates.io crates.io crates.io



Macro for converting Structure to green-barrel Model. The model can access the database. The model can create, update, and delete documents in collections.


Model parameters

( all parameters are optional )

Parameter: Default: Description:
db_query_docs_limit 1000 limiting query results.
is_add_doc true Create documents in the database. false - Alternatively, use it to validate data from web forms.
is_up_doc true Update documents in the database.
is_del_doc true Delete documents from the database.
ignore_fields empty string Fields that are not included in the database (separated by commas).
is_use_add_valid false Allows additional validation - impl AdditionalValidation for ModelName.
is_use_hooks false Allows hooks methods - impl Hooks for ModelName.

Install mongodb (if not installed)

### Ubuntu, Mint:
$ sudo apt install mongodb
## OR
### Ubuntu 20.04, Mint 20.x:
$ sudo apt update
$ sudo apt install dirmngr gnupg apt-transport-https ca-certificates
$ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
$ sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse'
$ sudo apt update
$ sudo apt install mongodb-org
$ sudo systemctl enable --now mongod
# For check
$ mongod --version
$ mongo --eval 'db.runCommand({ connectionStatus: 1 })'
$ reboot
### Configuration file:
$ sudo nano /etc/mongod.conf
### Systemd:
$ sudo systemctl status mongod
$ sudo systemctl start mongod
$ sudo systemctl stop mongod
$ sudo systemctl restart mongod
$ sudo systemctl enable mongod
$ sudo systemctl disable mongod
### Uninstall:
$ sudo systemctl stop mongod
$ sudo systemctl disable mongod
$ sudo apt --purge remove mongodb\*  # OR (for mongodb-org) - $ sudo apt --purge remove mongodb-org\**
$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb
$ sudo rm -f /etc/mongod.conf
$ sudo apt-add-repository --remove 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse' # for mongodb-org
$ sudo apt update


Basic Example


  • v1.3.2-beta Fixed basic example and updated readme file.
  • v1.3.0-beta Transition to asynchronous code.
  • v1.2.0-beta Updated dependency mongodb to version 2.
  • v1.1.9-beta Updated README.md file.
  • v1.1.0-beta Added support for Fixtures - To populate the database with pre-created data.
  • v1.0.0-beta Not compatible with green-barrel v0.x.x and metamorphose v0.x.x
  • v0.7.12 Fixed README.md.
  • v0.7.8 Fixed validation for multi-select fields.
  • v0.7.0 Added trait Administrator for easier registration of Models in the administration panel.
  • v0.6.10 Added the ability to customize html code for web forms. See documentation: mango_orm > widgets > generate_html_code > GenerateHtmlCode > generate_html().
  • v0.6.9 Rename trait ToModel to Main.
  • v0.6.0 The created_at and updated_at fields are automatically added to the Model. The widget type is inputDateTime and disabled = true, is_hide = true. Updated README.md. Updated documentation.
  • v0.5.4 Fixed ModelName::key() method. See documentation: mango_orm > models > ToModel.
  • v0.5.2 Import optimized.
  • v0.5.0 Added model attribute is_use_hooks. See documentation: mango_orm > models > hooks > Hooks.
  • v0.4.8 Fixed error message text.
  • v0.4.6 Updating by version of dependencies.
  • v0.4.4 Optimization of the validation mechanism.
  • v0.4.3 Improved validation for Slug fields.
  • v0.4.2 Removed hiddenSlug field.
  • v0.4.1 Added is_hide parameter for Widgets.
  • v0.4 Added inputSlug and hiddenSlug fields.
  • v0.3 Removed the Form macro.


This project is licensed under the MIT and Apache Version 2.0


~617K SLoC