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)
MongoDB is one of the popular open-source NoSQL databases. In this article, we will take a look at how we can use it in flutter apps. In this example, we will use mongo_dart package which is a server-side driver library for MongoDB that is implemented in pure dart language.
Access the App ClientFind the App ID in the Realm UI. Create an AppConfiguration object with your App's App ID as the argument. Create an App with the AppConfiguration you just created. You use this App instance to access App Services features throughout your client application.
MongoDB allows teams to choose their cloud provider of choice while providing database management that streamlines every aspect of database administration. It's easy to get started with MongoDB Atlas, and it's free.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With