Golang MongoDB Model Generator with CRUD
Create ready-to-go models when working with the Official Go Driver for MongoDB including CRUD Operations (Create, Read, Update, Delete).
go get -u github.com/aliforever/gomondel
Note: Run go install
after go get
to install gomondel in bin folder located at %GOPATH%/bin (make sure bin folder is added to path variable).
To add database connection to your project:
-
cd into your project directory, forexample:
cd %GOPATH%/src/myproject/
, and then run:gomondel --init=your_database_name_here
(This will create a models folder with a db.go file)
-
call
models.InitMongoDB()
in your main file to initialize the database.
To create a new model based on your MongoDB collections, run:
gomondel --model=ModelName
(This will create modelname.go file in models folder)
gomondel uses Inflect Package to pluralize model names, so forexample if your collection name is users
, you should use User
as model name.
This is to comply to golang naming conventions, your model struct type will be named User.
You're free to create issues and pull requests to help complete gomondel!