basic

command module
v0.0.0-...-895af31 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: MIT Imports: 9 Imported by: 0

README

Connecting to MongoDB

An example of how you would connect to MongoDB and perform basic CRUD operations.

Requirements

  • MongoDB version 4 and above.

Setup

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

    $ docker-compose up
    
  2. You can connect to Mongo via the console:

    $ docker exec -it mongo mongo -u nobody -p secrets go-recipes
    
  3. You can press CTRL-C and CTRL-D on the mongo-server and mongo-cli respectively to stop the containers. Don't forget to remove the containers as well.

    $ # This should remove both mongo-server and mongo-cli
    $ docker-compose down
    
  4. Run Go programL

    $ go run ./main.go
    
  5. Alternatively, you can run everything with the following command.

    $ make
    

Notes

  • We deliberately hard code the password to connect to MongoDB to keep the sample code simple and easy to understand. Do not do this in your code, especially production code.

Reference and Credits

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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