【问题标题】:Unable to connect mongodb atlas to intellij MongoExplorer无法将 mongodb atlas 连接到 intellij MongoExplorer
【发布时间】:2017-12-06 20:56:19
【问题描述】:

我正在使用 mongodb atlas 作为我的后端,我正在尝试将它连接到 intellij 的 Mongo Explorer

这是详细信息的第一张图片

这是我提供数据库用户名和密码但仍然无法连接的第二张图片。

我已经很容易地连接到 localhost 没有任何问题,但这没有连接...

我正在使用具有学生许可的 Intellij Idea Ultimate 2017.1.3。我认为这个特定的许可证和 Ide 版本没有问题

提前致谢:)

【问题讨论】:

  • 检查您的服务器网址字段。与docs.mongodb.com/manual/reference/connection-string比较
  • 是的,它与指定的格式匹配它看起来像这样 mongodb://practice:@cluster0-shard-00-00-shj3q.mongodb.net:27017,cluster0-shard-00 -01-shj3q.mongodb.net:27017,cluster0-shard-00-02-shj3q.mongodb.net:27017/?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin
  • 给定的url格式为mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/ [数据库][?options]]
  • 您是否尝试过服务器 url 中的 cluster0-shard-00-00-shj3q.mon‌​godb.net:27017, clust‌​er0-shard-00-01-shj3‌​q.mongodb.net:27017,‌​cluster0-shard-00-02‌​-shj3q.mongodb.net:2‌​7017 ,如下所述的预期格式?
  • @Andrey 是的,我已成功连接它。只需通过 cmets 即可。因为很长一段时间我都忘记了我实际上做了什么,但我肯定做了一些在 cmets 中解释过的事情。

标签: node.js mongodb intellij-idea mongodb-atlas


【解决方案1】:

步骤很简单:

  1. 在 pom.xml 文件中添加这些依赖项:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    

  2. 您想将此代码添加到 application.properties 文件中:

     spring.data.mongodb.uri= your_uri_here
     spring.data.mongodb.database= database_name_here
    

【讨论】:

  • 我的是节点项目而不是 spring 项目。
【解决方案2】:
mongodb+srv://admin:<password>@clust‌​er0-shard-00-01-shj3‌​q.mongodb.net/test?retryWrites=true

【讨论】:

  • 也许您应该详细说明为什么这是问题的解决方案。
猜你喜欢
  • 2021-06-25
  • 2020-09-13
  • 2019-10-31
  • 2019-06-08
  • 2019-10-13
  • 1970-01-01
  • 2019-12-24
  • 2020-02-22
  • 2020-07-25
相关资源
最近更新 更多