basheps
basheps

Reputation: 10604

Dart with MongoDB

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)

Upvotes: 7

Views: 5013

Answers (2)

Ross Albertson
Ross Albertson

Reputation: 101

I've had a lot of trouble with MongoDB in client-side Dart myself. I ended up moving the Mongo calls to the back end, and using a combination of REST and Json to communicate between the two ends. You can find an example I wrote at https://github.com/RossBabcock3/dartgo3

Upvotes: 0

Vadim Tsushko
Vadim Tsushko

Reputation: 1516

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:[email protected]: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.

Upvotes: 7

Related Questions