简体   繁体   中英

How to use AWS Document DB with Ruby On Rails? Compatibility with version 3.6?

recently AWS implemented compatibility with MongoDB version 3.6 via DocumentDB.

Document DB requires a certificate that can be downloaded at:

https://s3-us-gov-west-1.amazonaws.com/rds-downloads/rds-GovCloud-Root-CA-2017.pem

Using a configuration file similar to:

https://github.com/mongodb/mongoid/blob/master/lib/rails/generators/mongoid/config/templates/mongoid.yml

I would like to know if there is a way to set compatibility with 3.6 in mongoid gem or if there is a specific version that ensures that version 3.6 is used?

Thank you

First, it is important to note that DocumentDB implements only partial compatibility with "MongoDB 3.6" as Amazon advertises. You can read more about some of the incompatibilities here: https://www.mongodb.com/blog/post/documents-are-everywhere

Mongoid works, and is tested, with the actual MongoDB 3.6 server. No special configuration is needed.

Using Mongoid with DocumentDB may work or may expose incompatibilities/omissions in Amazon's document database, depending on exact operations attempted.

First, you may need to download the RDS combined bundle as opposed to the rds-GovCloud-Root-CA-2017.pem . Link: https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem

Try this as your yaml file:

development:
  clients:
    default:
      uri: mongodb://myuser:mypassword@<your_cluster_endpoint>:<cluster_port>/test?ssl=true
      options:
        ssl_ca_cert: /path/to/rds-combined-ca-bundle.pem

Sample Working Configuration

production:
    clients:
        default:
            uri: "mongodb://user:pass@db_end_point:27017/db_name?ssl=true&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false"
            app_name: AppName
            options:
                ssl_ca_cert: "./config/rds-combined-ca-bundle.pem"

development:
    clients:
        default:
            uri: "mongodb://user:pass@db_end_point:27017/db_name?ssl=true&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false"
            app_name: AppName
            options:
                ssl_ca_cert: "./config/rds-combined-ca-bundle.pem"


test:
    clients:
        default:
            uri: "mongodb://user:pass@db_end_point:27017/db_name?ssl=true&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false"
            app_name: AppName
            options:
                ssl_ca_cert: "./config/rds-combined-ca-bundle.pem"

as of 2022, aws provided uri with protocol( mongodb ://) and query seems not working with mongoid..?

( as I got error below

Mongoid::Errors::MixedClientConfiguration: message: Both uri and standard configuration options defined for client: 'default'.

then, I modified config/mongoid.yml

working example should be like this:


development:
  clients:
    default:
      database: your_db
      hosts:
        - xxx.ap-northeast-1.docdb.amazonaws.com:27017
      options:
        user: mongo_user
        password: password
        ssl: true
        ssl_verify: false
        ssl_cert: path/to/rds-combined-ca-bundle.pem

reference:

https://github.com/mongodb/mongoid/blob/master/lib/rails/generators/mongoid/config/templates/mongoid.yml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM