How can I connect to MongoDB server using JAVA from OpenShift?

前端 未结 1 1863
面向向阳花
面向向阳花 2021-01-22 13:51

I have created a MongoDB instance in OpenShift. I can connect to it via RockMongo, which is a service offered by OpenShift.

相关标签:
1条回答
  • 2021-01-22 14:38

    OpenShift provides environment variables, which you should use to connect to your MongoDB.

    • OPENSHIFT_MONGODB_DB_HOST The MongoDB IP address
    • OPENSHIFT_MONGODB_DB_PORT The MongoDB port
    • OPENSHIFT_MONGODB_DB_USERNAME The MongoDB username
    • OPENSHIFT_MONGODB_DB_PASSWORD The MongoDB password
    • OPENSHIFT_MONGODB_DB_URL The MongoDB connection URL (e.g. mongodb://<username>:<password>@<hostname>:<port>/)

    I'm using one line of code to connect to the database:

    new MongoClient(new MongoClientURI(System.getenv("OPENSHIFT_MONGODB_DB_URL")));
    
    0 讨论(0)
提交回复
热议问题