title: How to fix 'MongoDart Error: Db is in the wrong state: State.OPENING' in Flutter?
body: <p>I'm making an app in Flutter that should connect to a MongoDB on a remote server for some functionality (login for example). The problem is that it doesn't matter which server I try to connect to (my computer's or my Google Cloud); I get the same error <code>"Unhandled Exception: MongoDart Error: Db is in the wrong state: State.OPENING"</code>. In the catch-handler I also get this error: <code>"failed SocketException: OS Error: Connection timed out, errno = 110, address = 10.0.2.2, port = 54167"</code>. How can I fix that?</p>
  
  <p>I use the plugin from <a href="https://pub.dartlang.org/packages/mongo_dart" rel="nofollow noreferrer">https://pub.dartlang.org/packages/mongo_dart</a> and try to make my function as easy as possible just to see if I can interact with the server in any way. I have changed the config so the servers allow for remote connection.</p>
  
  <pre><code>openDB() async {
      //mongo.Db db = new mongo.Db("mongodb://URLtoServer:27017/mongotest");
      mongo.Db db = new mongo.Db("mongodb://10.0.2.2:27017/mongotest"); //toHostComputer
      try {
        await db.open();
      } catch (e) {
        print('failed ${e.toString()}');
      }
      var loginColl = db.collection('LogIn');
      var res = await loginColl.findOne();
      print('$res');
      await db.close();
    }
  </code></pre>
  
  <p>I expected the output to be an example from my collection 'LogIn', but what I instead get is the errors listed above. Therefore I guess that the error must be on the Android Studio Side rather than the server. Any help is very appreciated!</p>