MongoDB - EDITOR 变量 - MongoDB shell - Windows 7 [英] MongoDB - EDITOR variable - MongoDB shell - Windows 7

查看:61
本文介绍了MongoDB - EDITOR 变量 - MongoDB shell - Windows 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EDITOR 变量功能真的适用于 Windows 7 吗?

Is the EDITOR variable feature really working on Windows 7?

我在读一篇文章,说一旦我们设置了 EDITOR 变量
在 .mongorc.js 中,我们只需在 shell 中输入:edit var_name
并且 var_name 将被加载到 EDITOR(在我的例子中是 UltraEdit)
用于编辑.完成更改后,我们就可以
保存并退出编辑器;然后将解析变量
并加载回外壳.
粗斜体部分
对我不起作用.

I am reading a text saying that once we set the EDITOR variable
in .mongorc.js we can just type in the shell: edit var_name
and var_name will be loaded in the EDITOR (UltraEdit in my case)
for editing. Once we're done making the changes, we can just
save and exit the editor; then the variable will be parsed
and loaded back into the shell.
The part in bold italic
does not work for me.

它所做的只是让我在桌面上保存一些 js 文件?!

All it does is offering me to save some js file on my desktop?!

有什么想法吗?

我注意到如果我将它设置为记事本(notepad.exe"),
它工作正常.但是如果我将它设置为 UltraEdit(uedit32.exe"),
它不像人们期望的那样工作.

推荐答案

EDITOR 环境变量适用于 Windows,但在 MongoDB 2.4 中,似乎有一些影响可用性的因素.

The EDITOR environment variable works on Windows, but it looks like there are a few factors that affect usability as at MongoDB 2.4.

当您使用 edit 命令时,mongo shell 会使用该变量的内容和 使用此文件路径启动外部编辑器.然后 shell 会话等待编辑器退出并检查返回码.

When you use the edit command, the mongo shell writes a temporary JavaScript file with the contents of that variable and launches the external editor with this file path. The shell session then waits for the editor to exit and checks the return code.

如果出现以下情况,则效果不佳:

This doesn't work well if:

  • 外部编辑器有一个多文档界面,并且已经有其他文档打开

  • the external editor has a multiple-document interface and there are already other documents open

外部编辑器未返回预期的 0(无错误)返回代码

the external editor doesn't return the expected 0 (no errors) return code

  • 限制自己使用单个文档编辑器进行 EDITOR 设置.虽然 notepad.exe 可以工作,但可能有一个更强大的编辑器,包括 JavaScript 语法突出显示.

  • Limit yourself to using a single document editor for your EDITOR setting. While notepad.exe works, there is likely a more capable editor that includes JavaScript syntax highlighting.

如果您正在开发复杂的 JavaScript 函数,您可能希望将这些函数保存在外部文件中.您可以使用 load("/path/to/file.js") 将最新版本的 JS 文件重新加载到 shell 中.

If you are developing complex JavaScript functions, you probably want to have those in an external file. You can use load("/path/to/file.js") to reload the latest version of a JS file into the shell.

UltraEdit 有一些额外的用户体验问题(我用 UltraEdit V20 测试过):

UltraEdit has some extra user experience wrinkles (I tested with UltraEdit V20):

  • (运气好)如果您在从 mongo shell 调用 edit 之前没有打开 UltraEdit 不要打开任何额外的选项卡,它将作为外部编辑器工作.您应该能够成功使用 mongo shell 中的 edit 来启动 UltraEdit,编辑变量,并查看关闭 UltraEdit 时保存的结果.UltraEdit 提示将更新后的 JS 文件保存在同一位置.

  • (works with luck) if you don't have UltraEdit open before you invoke edit from the mongo shell and don't open any extra tabs, it will work as an external editor. You should be able to successfully use edit from the mongo shell to launch UltraEdit, edit a variable, and see the results saved when you close UltraEdit. UltraEdit prompts to save the updated JS file in the same location.

(不起作用)如果 UltraEdit 已经打开并且有其他文档标签,它会有不同的行为.来自 mongo shell 的 edit 命令将打开一个新选项卡,但是当您关闭此选项卡(以保存更改)时,UltraEdit 会提示另存为"对话框.UltraEdit 保存了 JS 文件,但显然没有返回预期的退出代码,因此 mongo shell 不知道 JS 文件已更新,应该重新加载.

(doesn't work) if UltraEdit was already open and has other document tabs, it has different behaviour. The edit command from the mongo shell will open a new tab, but when you close this tab (to save changes) UltraEdit prompts with a "Save as" dialog. UltraEdit saves the JS file, but apparently doesn't return the expected exit code so the mongo shell is unaware that the JS file has been updated and should be reloaded.

感谢 UltraEdit Expert 的建议,我找到了一个使 UltraEdit 运行良好的配置设置:

Thanks to UltraEdit Expert's suggestions, I found a configuration setting that makes UltraEdit work nicely:

  • 打开配置设置(高级 > 配置 菜单)
  • 应用程序布局>杂项下,启用设置为从外部应用程序打开的每个文件维护单独的进程
  • 重新启动 UltraEdit(该设置似乎要到下次启动才会生效)

启用单独进程"设置后,您现在应该能够将 UltraEdit 作为外部 EDITOR 使用,并在关闭从 mongo<打开的编辑选项卡时看到反映的更改/code> 外壳.

With the "separate process" setting enabled, you should now be able to use UltraEdit as an external EDITOR and see the changes reflected when you close the editing tab opened from the mongo shell.

这篇关于MongoDB - EDITOR 变量 - MongoDB shell - Windows 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆