Everytime I try to connect to my local MongoDB, I keep getting this Exception: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 38748
Fun fact: the port in the exception increments by two after each try and is always wrong (I even started the server with the port throwing the exception next)
MongoDB server is running - I NETWORK [initandlisten] waiting for connections on port 27017
Dependency is set -
dependencies: mongo_dart: ^0.3.5 flutter: sdk: flutter
import 'package:mongo_dart/mongo_dart.dart' show Db, DbCollection;
class DBConnection {
static DBConnection _instance;
final String _host = "localhost";
final String _port = "27017";
final String _dbName = "debtservice";
Db _db;
static getInstance(){
if(_instance == null) {
_instance = DBConnection();
}
return _instance;
}
Future<Db> getConnection() async{
if (_db == null){
try {
_db = Db(_getConnectionString());
await _db.open();
} catch(e){
print(e);
}
}
return _db;
}
_getConnectionString(){
return "mongodb://$_host:$_port/$_dbName";
}
closeConnection() {
_db.close();
}
}
I already tried to run this code in plain dart and it runs.