Databases
letsgo currently supports mongodb only.
letsgo will have support for most common databases in near future.
Table of contents:
MongoDB Installation
Install MongoDB locally
Please follow this installation guide.
Connecting to MongoDB
.env
as per your requirement.
Fill the environment variable in DATABASE_HOST=127.0.0.1
DATABASE_PORT=27017
DATABASE=todo_api
./main.go
To Connect to the database add the following lines in package main
import (
...
"github.com/letsgo-framework/letsgo/database"
...
)
func main() {
...
...
database.Connect()
...
}
./database/collections.go
create a function that returns a collection
Define a collection: in package database
import "go.mongodb.org/mongo-driver/mongo"
func UserCollection() *mongo.Collection {
return DB.Collection("users")
}
DB.Collection("users") will perform all mongo-go-driver actions