In this video series, we will learn how to talk to a MongoDB database with Dart, using the mongo_dart package. MongoDB is a well-known NoSQL database that stores its items as JSON documents (BSON to be exact). At the end of this video, you will be comfortable setting up a MongoDB database, connecting to your database, creating your own collections and performing CRUD operations.

Prerequisites

Download and checkout the starter branch to follow along. You will learn much better this way. I know it’s convenient just watching, but doing will be much more fulfilling☺️

In the root directory of the project run pub get to update your dependencies.

Setup your database

Run Mongo server running using the startup commands on the documentation page for your Operating System.

Log in to MongoDB by entering mongo in the terminal. Create a database and collection:

> use test; switched to db test > db.createCollection('people'); { "ok" : 1 } > exit bye

Upload the people.json file into the people collection we just created.

$ mongoimport --jsonArray -d test -c people --file people.json ... connected to: localhost ... imported 100 documents

To confirm all is good, log in to Mongo and check the collection:

$ mongo ... > use test switched to db test > show collections people > db.people.find(); [{ "id": 1, "first_name": "Nolly", "last_name": "Montfort", "email": "nmontfort0@archive.org", "gender": "Male", "ip_address": "6.125.126.90" }, ... ... ]

Good job! Let’s continue with the video.

Continue watching

Sharing is caring

If you enjoyed reading this post, please share this through the various social buttons hovering on the left/top side of the screen . Also, check out and subscribe to my YouTube channel (hit the bell icon too) for videos on Dart.

Subscribe to the newsletter for my free 35-page Get started with Dart eBook and to be notified when new content is released.

Like, share and follow me for more content on Dart.