mongodb - 带有特殊字符(特别是 & 符号)的 Heroku 配置
问题描述
我有一个 Heroku 应用程序,它需要一个带有与号 (&) 的 URI 作为配置变量。具体来说,它是一个 MongoDB Atlas 连接字符串,但这不是重点。根据Heroku Docs,我应该像这样格式化这个 CLI 命令:
heroku config:set exampleVar=www.bar.com?a=b&c=d&e=f&justkey
但是,当我尝试实际运行该命令时,我得到以下信息:
Setting exampleVar and restarting ⬢ example-heroku-app... done, v10
exampleVar: www.bar.com?a=b
'c' is not recognized as an internal or external command,
operable program or batch file.
'e' is not recognized as an internal or external command,
operable program or batch file.
'justkey' is not recognized as an internal or external command,
operable program or batch file.
看来这个&
角色正在让 Heroku 将它后面的内容解释为命令?我猜我需要以某种方式逃避它,但我不知道如何。转换&
为\&
无效,添加单引号或双引号也无效。如果有人在这里有答案,请赐教!我似乎找不到关于 Heroku Config 的特殊字符规则的像样的文档。
解决方案
将 & 字符用双引号括起来。下面是一个例子。
heroku config:set MONGODB_URL='mongodb+srv://hello:test@cluster0.y6red.mongodb.net/fdert?retryWrites=true"&"w=majority'
请注意单引号和双引号的使用。
推荐阅读
- python - 我想检测不同光线条件下的激光点(圆)
- arrays - js中如何从数组中删除元素【元素来自mongodb】
- angular - 如何在 Linux 机器中自动重新加载 Angular 4 测试用例。
- c# - 如何在 C# 中序列化和反序列化 geojson
- jquery - 如何使用节点在我的代码中正确要求 jquery 和 JSDOM?
- node.js - AWS SKD node.js - getMetricData 不是函数
- arrays - Angular PrimeNG DataTable 将嵌套的 JSON 显示为一列中的自定义字符串
- c# - Cosmo Sql Db - 使用延续令牌查询数据永远不会完成
- python - 在 NumPy 中将单列添加到矩阵中
- oracle - ORA-00904:“PSTATUSTYPE”:无效标识符 00904。00000 -“%s:无效标识符”*原因:*操作:第 67 行错误,第 11 列