Skip to content

This repository can help you to integrate a MongoDBAtlas cluster database into your Go application and test the operations of creating, reading, updating, and deleting documents from a collection.

License

Notifications You must be signed in to change notification settings

chriscodex/Integrations-Tests-MongoDBAtlas-Go

Repository files navigation

Integration Tests to MongoDBAtlas with Go GitHub go.mod Go version

This repository can help you to integrate a MongoDBAtlas cluster database into your Go application and test the operations of creating, reading, updating, and deleting documents from a collection.

ITMDBG


Table of Contents 📖

  1. Pre-Requirements
  2. Installation
  3. Run Tests

Pre-Requirements 📋

Have access to a MongoDBAtlas cluster.
In this link you have a guide on how to create it: https://www.mongodb.com/docs/atlas/tutorial/create-new-cluster/


Installation 🔧

  • Install the MongoDB driver as a dependency
go get go.mongodb.org/mongo-driver/mongo  
  • Inside the database folder, modify the mongodb.con.go file. Add the uri of your cluster and the name of your database
var (
	// Add the uri of your cluster of MongoDBAtlas
	// https://www.mongodb.com/docs/drivers/go/current/quick-start/#connect-to-your-cluster
	uri = ""
	// Add the name of your database
	database = ""
)

Run Tests ⚙️

To run the test, type this command:

go test
  • To verify the connection, run the test inside /database directory.
  • To test CRUD operations, run the test inside /service/user.service directory.
    By default it will create the "users" collection, if you want to change the collection, modify the user.repository.go file located inside /repositories/user.repository/
// Name of collection
var collection = database.GetCollection("users")

About

This repository can help you to integrate a MongoDBAtlas cluster database into your Go application and test the operations of creating, reading, updating, and deleting documents from a collection.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages