Not bad for 34 lines of code, considering that about half of that was just defining the imports for packages to be used within the project. Inside the main function, let's establish a connection to our MongoDB Atlas cluster: func main() ) Most logic, at least for now, will exist in the main function. The above code represents the imported modules within the MongoDB Go Driver that will be used throughout the tutorial series. With the driver installed, open the project's main.go file, and add the following imports to the code: package main For more information about Go modules, see. If using Go 1.11, this requires the quickstart module to be created outside $GOPATH/src if you also have a $GOPATH set up. Note that for this tutorial we are using Go modules to manage our packages. To do this, execute the following from the command line: $ go mod init quickstart The next step is to install the MongoDB Go Driver using Go modules. We can start the main.go file with the following boilerplate code, necessary for our dependency manager: package main ![]() Getting StartedĬreate a new project directory titled quickstart, and add a main.go file to that project.įor this particular tutorial, all code will be added to the main.go file. If you're using a different IDE, O/S, etc., the walk-through might be slightly different, but the code will be pretty much the same. ![]() MongoDB Atlas offers a forever FREE tier that can be accessed within the MongoDB Cloud.
0 Comments
Leave a Reply. |