mongorestore 可以采用单个 url 参数而不是单独的参数吗? [英] Can mongorestore take a single url argument instead of separate arguments?
问题描述
如果我有以下格式的 mongo 数据库 URL
If I have a mongo database URL of the following format
mongodb://someUsername:somePassword@some.server.com:27017/some_collection
是否有一种简单的方法可以将其提供给 mongorestore
而无需这样做
Is there an easy way to give this to mongorestore
without having to do
mongorestore -u someUsername -p somePassword -h some.server.com:27017 -db some_collection /path/to/dump
我问的原因是因为 meteor mongo --url
返回该形式的 url(它看起来像一个标准化的 url 格式)但它 一分钟后到期.因为密码和主机可能很长,我是否可以在一分钟内(正确)复制参数,通常需要多次尝试.
The reason I ask is because meteor mongo --url
gives back a url of that form (and it looks like a standardized url format) but it expires in one minute. Because the password and host can be pretty long, it's hit or miss whether I can copy the parameters over (correctly) in one minute, and usually requires several tries.
是否存在类似以下内容?
Does something like the following exist?
mongorestore --url blah_blah /path/to/dump
另见https://stackoverflow.com/a/15865565/586086
推荐答案
我没有找到将 URL 作为参数传递的方法,但我写了一个将 URL 转换为 mongorestore 参数的单行命令:
I didn't find a way to pass the URL as a parameter but I wrote a one line command that converts the url into mongorestore parameters:
CMD=`meteor mongo -U autocomplete.meteor.com | tail -1 | sed 's_mongodb://([a-z0-9-]*):([a-f0-9-]*)@(.*)/(.*)_mongorestore -u 1 -p 2 -h 3 -d 4_'`
$CMD /path/to/dump
这篇关于mongorestore 可以采用单个 url 参数而不是单独的参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!