Skip to content

Instantly share code, notes, and snippets.

@lefloh
Created July 24, 2014 18:10
Show Gist options
  • Save lefloh/70b8bdad7eef12949876 to your computer and use it in GitHub Desktop.
Save lefloh/70b8bdad7eef12949876 to your computer and use it in GitHub Desktop.
mongo-dart-test
import 'dart:async';
import 'package:mongo_dart/mongo_dart.dart';
class MongoTest {
Db _db = new Db('mongodb://localhost/test');
insert() {
_db.open().then((_) {
return _db.collection('foo').insertAll([{ 'foo': 'bar' }]);
}).then((_) => _db.close());
}
Future find() {
return _db.open().then((_) {
return _db.collection('foo').find().toList();
}).then((val) {
_db.close();
return val;
});
}
}
main() {
var mongoTest = new MongoTest();
//mongoTest.insert();
mongoTest.find().then((x) => print(x));
// second call causes NoSuchMethodError: method not found: 'query'
//mongoTest.find().then((x) => print(x));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment