Book Image

Learning Dart, Second Edition - Second Edition

By : Ivo Balbaert
Book Image

Learning Dart, Second Edition - Second Edition

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Learning Dart Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using the mongo_dart driver to store the todo data in MongoDB


MongoDB drivers exist for a whole range of programming languages, including Dart. We will use mongo_dart in our app, which is a server-side driver implemented purely in Dart. Simply add mongo_dart: any to your app's pubspec.yaml and issue pub install. In the code, write:

import 'package:mongo_dart/mongo_dart.dart';

The todo_mongodb version is a version of todo_server_dartling_mysql, but we will now use MongoDB as a persistent data source (clone the project from https://github.com/dzenanr/todo_mongodb). It contains a todo_client_idb client app identical to the one in the previous section, which stores data in IndexedDB. The todo_server_dartling_mongodb server part can be started by running bin/server.dart. You should see the following output in the editor or the console:

Server at http://127.0.0.1:8080;

If you see the following exception, it means that the mongod server has not yet been started:

SocketException: Connection failed...