Creative Bracket

Dart and MongoDB Tutorial #1: Using the mongo_dart package

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.

Watch my Free Get started with Dart course on Egghead.io and Subscribe to my email newsletter to download my Free 35-page eBook titled Get started with Dart and to be notified when new content is released.

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

Jermaine Oppong

Hello πŸ‘‹, I show programmers how to build full-stack web applications with the Dart SDK. I am passionate about teaching others, having received tremendous support on sites like dev.to and medium.com for my articles covering various aspects of the Dart language and ecosystem.

5 comments