MongoDB 凭据在通过 GitHub 进行 OpenShift 部署期间



我想使用 openshift 来托管我的 nodejs 和 mongodb 应用程序。 我的MongoDB正在MONGO Atlas上托管。

但是,openshift 要求我将我的应用程序上传到 github 上进行部署。 我的问题是在这种情况下如何存储我的用户名和 mongodb 凭据。显然,我不能只是在github上推送密码并将其公开。

我的连接语句是

服务器.js

var conString = "mongodb://username:password@cluster0-shard-00-00-e2zhz.mongodb.net:27017,cluster0-shard-00-01-e2zhz.mongodb.net:27017,cluster0-shard-00-02-e2zhz.mongodb.net:27017/chat?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin"
//var conString = "mongodb://localhost:27017/mylearning";
app.use(express.static(__dirname))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
mongoose.Promise = Promise
var Chats = mongoose.model("Chats", {
name: String,
chat: String
})
mongoose.connect(conString, { useMongoClient: true }, (err) => {
console.log("Database connection", err)
})

使用机密。文档可在以下位置找到:

  • https://docs.openshift.com/container-platform/3.7/dev_guide/secrets.html

另请查看"部署到 OpenShift"一书的"配置和机密"章节:

  • https://www.openshift.com/promotions/deploying-to-openshift.html

这本书是免费下载的。

你也不必把你的代码放在GitHub上。可以使用二进制输入生成。那本书也谈到了这一点。

相关内容

最新更新