0

我们正在尝试连接到aws docdbfrom errbit,但没有运气。这是来自 docdb 的连接字符串:

mongodb://user:<insertYourPassword>@dev-docdb-cluster.cluster-xxxx.us-east-1.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0

虽然我们能够连接到 Atlas db,但我们用于 atlas 的连接字符串格式是这样的:

mongodb://user:pass@cluster-shard-00-00-xxx.mongodb.net:27017,cluster-shard-00-01-xxx.mongodb.net:27017,cluster-shard-00-02-xxx.mongodb.net:27017/errbit?ssl=true&replicaSet=Cluster-shard-0&authSource=admin&w=majority
4

1 回答 1

0

您需要将config/mongo.rb文件更改为如下:

log_level = Logger.const_get Errbit::Config.log_level.upcase

Mongoid.logger.level = log_level
Mongo::Logger.level = log_level

Mongoid.configure do |config|
  uri = if Errbit::Config.mongo_url == 'mongodb://localhost'
          "mongodb://localhost/errbit_#{Rails.env}"
        else
          Errbit::Config.mongo_url
        end

  config.load_configuration(
    clients: {
      default: {
        uri: uri,
        options: { ssl_ca_cert: Rails.root.join('rds-combined-ca-bundle.pem') }
      }
    },
    options: {
      use_activesupport_time_zone: true
    }
  )
end

您可以注意到这与当前的完全相同,除了我添加了: options: { ssl_ca_cert: Rails.root.join('rds-combined-ca-bundle.pem') }

这样做后它确实对我有用 :) 当然,您需要rds-combined-ca-bundle.pem文件存在于 Rails 根文件夹中。

wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem

是的,我必须使用以下代码创建一个 docker 映像:

FROM errbit/errbit:latest
LABEL maintainer="Tarek N. Elsamni <tarek.samni+stackoverflow@gmail.com>"

WORKDIR /app

RUN wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem

COPY ["mongo.rb", "/app/config/"]
于 2019-08-22T14:36:51.983 回答