8

If I have a mongo database URL of the following format

mongodb://someUsername:somePassword@some.server.com:27017/some_collection

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

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

See also https://stackoverflow.com/a/15865565/586086

Community
  • 1
  • 1
Andrew Mao
  • 35,740
  • 23
  • 143
  • 224

2 Answers2

6

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
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
acemtp
  • 2,971
  • 6
  • 34
  • 43
  • I updated your answer because the username generation has changed for Meteor. For reference, my script is at https://github.com/mizzao/meteor-autocomplete/blob/master/examples/pubsublocal/upload-db.sh – Andrew Mao Mar 13 '14 at 20:11
2

Update since five years ago:

Beginning with version 3.4.6, mongorestore accepts a URI argument:

https://docs.mongodb.com/manual/reference/program/mongorestore/#options

Andrew Mao
  • 35,740
  • 23
  • 143
  • 224