mongodb-go-driver-examples

module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2024 License: MIT

README

MongoDB Go Driver Examples

Overview

The purose of this repo is for me to learn how to use the MongoDB Go Driver and collate useful examples.

Requirements

Tool Description
Docker This is used to launch the MongoDB container
mongosh The MongoDB Shell
MongoDB for VS Code This is used to create a playground for MongoDB

MongoDB Container

For the purpose of a development environment, I'm using the mongo:latest image to launch a local development environment.

Run Docker MongoDB Container
docker-compose up -d
docker ps
docker volume ls
Shutdown the Docker Container
# Shutdown without deleting all containers
docker-compose stop
# Shutdown with deleting all containers
docker-compose down

VSCode MongoDB Extension

Please see the VSCode MongoDB extension documentation to see how to connect via the extension.

The connection string is mongodb://root:rootpassword@127.0.0.1/

Below is an example of what the connected database will look like via the extension:

MongodbExtention

Running the Sample Go Scripts

To tun the scripts, run the following command:

go run cmd/cli/main.go

You'll be prompted asking if you want to populate the DB with sample data. This only need to be done on the first run. You can see an example of this below:

UserPrompt

Appendix

Connect with Mongosh
mongosh admin -u root -p rootpassword

Directories

Path Synopsis
cmd
cli
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL