I have an app I am building in flutter and want to connect it to a database in mongo, but can't for the life of me get it to connect, here is a simple dart code to troubleshoot:
it always returns the error:
Unhandled exception: MongoDB ConnectionException: Could not connect to 127.0.0.1:27017 HandshakeException: Connection terminated during handshake
import 'package:mongo_dart/mongo_dart.dart';
import 'dart:io';
//Platform.environment['MONGO_DART_DRIVER_HOST']
//final mongoURI = Platform.environment['MONGO_DART_DRIVER_HOST'];
final url = "mongodb://127.0.0.1:27017/labelmask";
main() async {
Db _db = new Db(url);
await _db.open(secure: true);
print('connected');
}
Here is what I tried:
-I have tried using dart:io and get Platform.environments, but returned null
-Tried to connect to admin db instead of 'labelmask', same error
-I started first mongod and then mongo
-I can connect to this Database using python(pymongo) and from Compass GUI
-I can run mongo commands in terminal so I know it is connected, just not with dart