Dart with MongoDB

dart, mongodb

Solution

I believe you are running some old versions of mongo_dart samples. I belive if you would get fresh version either from github https://github.com/vadimtsushko/mongo_dart or from pub.dartlang.org samples and tests would run successfully. Corresponding line in fresh version of blog sample looks like:

Db db = new Db("mongodb://127.0.0.1/mongo_dart-blog");

And this is excerpt from comment for Db.open method

Db constructor expects valid mongodb URI. For example next code points to local mongodb server on default mongodb port, database testdb

var db = new Db('mongodb://127.0.0.1/testdb');

And that code direct to MongoLab server ds037637-a.mongolab.com on 37637 port, database blog, username dart, password test

var db = new Db('mongodb://dart:test@ds037637-a.mongolab.com:37637/blog');

Unfortunately API DOC on github site is very stale, due to old dartdoc bug: http://code.google.com/p/dart/issues/detail?id=5218

I hope it will be fixed soon and I'll be able to generate valid API doc for mongo_dart.

Problem

Are there any recent working examples on using Dart with MongoDB. All of the samples I'm trying are getting errors. Example below. Code: ``` import 'package:mongo_dart/mongo_dart.dart'; main(){ Db db = new Db("mongo-dart-blog"); // Throws an error. } ``` Error: ``` Unhandled exception: Invalid scheme in uri: mongo-dart-blog #0 Db.Db (package:mongo_dart/src/database/db.dart:25:7) #1 main (file:///.../MongoDart/app.dart:4:11) ```

Original source