# Running MongoDB Queries Concurrently With Go

DevFeed: [Running MongoDB Queries Concurrently With Go](<https://devfeed.tech/articles/running-mongodb-queries-concurrently-with-go-22095.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2014/02/running-queries-concurrently-against.html>)

Published: 2014-02-25T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [MongoDB](<https://devfeed.tech/topics/mongodb.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [concurrent](<https://devfeed.tech/tags/concurrent.md>), [drivers](<https://devfeed.tech/tags/drivers.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [go-types](<https://devfeed.tech/tags/go-types.md>), [golang](<https://devfeed.tech/tags/golang.md>), [goroutines](<https://devfeed.tech/tags/goroutines.md>), [mongodb](<https://devfeed.tech/tags/mongodb.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-languages](<https://devfeed.tech/tags/programming-languages.md>), [support](<https://devfeed.tech/tags/support.md>), [writing-code](<https://devfeed.tech/tags/writing-code.md>)

## AI overview

A beginner-oriented tutorial on using Go's mgo driver to connect to MongoDB and run queries concurrently. It demonstrates launching ten goroutines, querying a collection, and unmarshaling returned documents into native Go types.

## Source excerpt

If you are attending GopherCon 2014 or plan to watch the videos once they are released, this article will prepare you for the talk by Gustavo Niemeyer and Steve Francia. It provides a beginners view for using the Go mgo driver against a MongoDB database. Introduction MongoDB supports many different programming languages thanks to a great set of drivers. One such driver is the MongoDB Go driver which is called mgo. This driver has been externally developed by Gustavo Niemeyer from Canonical, and eventually Steve Francia, the head of the drivers team at MongoDB Inc, took notice and offered support. Both Gustavo and Steve will be talking at GopherCon 2014 in April about "Painless Data Storage With MongoDB and Go ". The talk centers around the mgo driver and how MongoDB and Go really work well together to build highly scalable and concurrent software. MongoDB and Go let us build scalable software on many different operating systems and architectures, without the need to install any frameworks or runtime environments. Go programs are native binaries and the Go tooling is constantly improving to create binaries that run as fast as equivalent C programs. That wouldn't mean anything if writing code in Go was complicated and as tedious as writing programs in C. This is where Go really shines because once you get up to speed, writing programs in Go is fast and fun. In this post I am going to show you how to write a Go program using the mgo driver to connect and run queries concurrently against a MongoDB database. I will break down the sample code and explain a few things that seem to be always be a bit confusing to those new to MongoDB and Go. Sample Program The sample program connects to a public MongoDB database I have hosted with MongoLab. If you have Go and Bazaar installed on your machine, you can run the program. The program launches ten goroutines that individually query all the records from the buoy_stations collection inside the goinggo database. The records are unma