https://github.com/muthukumar89uk/go-with-mongodb
This is a simple CRUD operation with golang and mongodb.
https://github.com/muthukumar89uk/go-with-mongodb
fiber-framework go golang mongodb-database rest-api
Last synced: about 2 months ago
JSON representation
This is a simple CRUD operation with golang and mongodb.
- Host: GitHub
- URL: https://github.com/muthukumar89uk/go-with-mongodb
- Owner: muthukumar89uk
- Created: 2024-07-26T11:00:54.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-08-01T08:29:16.000Z (10 months ago)
- Last Synced: 2025-02-13T14:37:09.553Z (3 months ago)
- Topics: fiber-framework, go, golang, mongodb-database, rest-api
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go MongoDB CRUD Example
This repository demonstrates how to set up a Go project to perform CRUD (Create, Read, Update, Delete) operations using MongoDB.
## Features
- MongoDB connection and operations in Go.
- CRUD operations.## Requirements
- Go 1.15 or higher
- MongoDB
- Fiber Go Web Framework## Getting Started
### Installation
1. **Clone the repository:**
```sh
git clone https://github.com/muthukumar89uk/go-with-mongodb.git
```
Click here to directly [download it](https://github.com/muthukumar89uk/go-with-mongodb/zipball/master).2. **Install Go dependencies:**
```sh
go mod tidy
```### Setup MongoDB
1. **Locally:**
Install MongoDB from the [official MongoDB website](https://www.mongodb.com/try/download/community).
### Go Application
1. **Create the `Employee` struct:**
Create a `models` directory and an `models.go` file with the following content:
```go
type Employee struct {
Id string `json:"id,omitempty" bson:"_id,omitempty"`
Name string `json:"name,omitempty" bson:"name,omitempty"`
Age int `json:"age,omitempty" bson:"age,omitempty"`
}
```### Run the Application
1. **Run the Go application:**
```sh
go run .
```2. **API Endpoints:**
- Create an employee: `POST /create`
- Get an employee by ID: `GET /getemployee`
- Update an employee by ID: `PUT /update-employees/:id`
- Delete an employee by ID: `DELETE /delete-employees/:id`