Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Connecting to MongoDB

An example of how you would connect to MongoDB and perform basic CRUD operations. In this example, we use a pre-defined schema that facilitates the mapping of MongoDB documents to Go data structures

There's another example that performs the same operation but without using a pre-defined schema.

Setup

Here's a sequence of steps to run this project.

  1. Launch a shell session and start MongoDB (server) via Docker:

    $ docker-compose up
  2. You can connect to Mongo via docker interactive tty interface.

    $ docker exec -it mongo mongo -u nobody -p secrets go-recipes
  3. Run Go program.

    $ go run ./main.go
  4. When you are done, just shut mongo down.

    $ docker-compose down
  5. Alternatively, you can run everything with just 2 commands.

    $ make
    $ make teardown    # Run this to remove the container

Reference and Credits