简体   繁体   English

你如何使用部署的流星应用程序运行mongo shell脚本?

[英]how do you run a mongo shell script with a deployed meteor app?

With mongo you can write scripts that get passed into the shell like: 使用mongo,您可以编写传递到shell中的脚本,如:

mongo myDB script.js

http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/ http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/

but to access the mongo shell of a deployed meteor app is says to do the following: 但要访问已部署的流星应用程序的mongo shell,请执行以下操作:

meteor mongo myApp.meteor.com

I can't pass the script file with this statement like so: 我无法像这样传递脚本文件:

 meteor mongo myApp.meteor.com script.js

because my deployed app is password protected and the above statement feeds script.js into the password prompt. 因为我部署的应用程序受密码保护,上面的语句将script.js提供给密码提示。

So the question is how would you do this? 所以问题是你会怎么做?

Alternatively how can you connect to a deployed meteor app's mongo shell without using meteor? 或者,如何在不使用流星的情况下连接到部署的流星应用程序的mongo shell?

Get the instance's login details via meteor mongo myapp.meteor.com --url . 通过meteor mongo myapp.meteor.com --url获取实例的登录详细信息。 You'll get something that should match up to 你会得到一些应该匹配的东西

mongodb:// username : password @ host : port / databasename mongodb:// username password @ host port / databasename

Which you can use to login via mongo on your computer. 您可以使用它在计算机上通过mongo登录。 Be aware the login details last for only 1 minute by which time you need to meteor mongo --url again 请注意登录详细信息仅持续1分钟,届时您需要再次使用meteor mongo --url

mongo host:port/databasename -u username -p password yourscript.js

Expanding a bit on Akshat's answer. 扩大Akshat的答案。 The URI string that meteor mongo --url puts out is a MongoDB Connection String . meteor mongo --url推出的URI字符串是MongoDB 连接字符串 It is a bit surprising that the mongo shell itself does not support this format. mongo shell本身不支持这种格式,这有点令人惊讶。 This has been reported as a bug ; 据报道是一个错误 ; also see this Stack Overflow answer . 另见Stack Overflow答案

It would be nice if meteor mongo had a way of passing parameters unparsed directly to the mongo shell. 如果meteor mongo有一种方法可以将未经分析的参数直接传递给mongo shell,那将会很不错。 Following a common Unix idiom it could've be something like: 遵循一个常见的Unix习语,它可能是这样的:

meteor mongo myapp.meteor.com -- myscript.js --some-other-mongo-parameter

But that does not work (I submitted a feature request ). 但这不起作用(我提交了一个功能请求 )。

I wrote a convenience wrapper for all the mongo client shell commands. 我为所有mongo客户端shell命令编写了一个便捷包装器。 You can install it with NPM: 你可以用NPM安装它:

npm install -g mmongo

If you don't use NPM, it's just a single file to drop somewhere in your $PATH ; 如果你不使用NPM,它只是一个文件放在$PATH某个地方; see the README at Github . 请参阅GithubREADME

You can now do: 你现在可以这样做:

mmongo myapp.meteor.com myscript.js 

Also see this answer for some examples. 一些例子也见这个答案

(There was previously a less featured script in Ruby here; see this Gist .) (以前在Ruby中有一个功能较少的脚本;请参阅此Gist 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM