【问题标题】:problem with flutter and mongodb connection颤振和mongodb连接的问题
【发布时间】:2020-03-09 18:48:47
【问题描述】:
import 'package:mongo_dart/mongo_dart.dart';

main() async{
  Db db = new Db("mongodb://localhost:27017/workouts");
  await db.open();
  print("success ---------------------------------");
}

这个简单的代码并没有连接,我不知道为什么。 这是输出:

Syncing files to device Android SDK built for x86...
Restarted application in 306ms.
E/flutter ( 5415): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 52206
E/flutter ( 5415): #0      _ConnectionManager._connect (package:mongo_dart/src/network/connection_manager.dart:23:5)

.... 还有更多日志

¿一些帮助? :(

【问题讨论】:

    标签: mongodb flutter dart


    【解决方案1】:

    已解决 ==> https://stackoverflow.com/a/55786011/12369361

    由于使用模拟器,我需要使用 10.0.2.2 而不是 localhost

    【讨论】:

      【解决方案2】:

      我想你有一个本地的 mongoDB 服务器。如果是这种情况,您必须将您的本地服务器和您的安卓手机连接到同一个网络(通过 wifi)。

      然后获取您本地服务器的 IP 并将您的 url 中的localhost 替换为您找到的 IP。

      如果不能,可能是您的防火墙阻止了您的请求。

      【讨论】:

      • 我尝试使用 IP 并且不工作,无论如何我使用 android studio 和 android mobile emulator
      • 好的。你的数据库有密码吗?
      猜你喜欢
      • 2019-11-16
      • 2020-04-03
      • 2019-03-13
      • 2021-05-27
      • 2021-11-16
      • 2021-05-05
      • 2022-01-12
      • 2021-10-20
      • 1970-01-01
      相关资源
      最近更新 更多