简体   繁体   中英

can't set an external editor in mongo shell.(Mac OS)

I want to set an external editor in mongo shell, but I get this error.

sh: /Applications/CodeRunner.app: is a directory
editor exited with error (32256), not applying changes

As the mongodb doc says, I did the following before starting mongo shell.

export EDITOR='/Applications/CodeRunner.app'
echo $EDITOR
/Applications/CodeRunner.app
open $EDITOR

I made sure that I can launch the editor 'CodeRunner' by running echo $EDITOR .

After this, I entered mongo shell and did the following but got the error.

var obj = {}
edit obj
sh: /Applications/CodeRunner.app: is a directory
editor exited with error (32256), not applying changes

Could please anyone tell me what I'm doing wrong and how to fix this error?

The MacOS .app "file" that you see in the Finder is in fact an application bundle with a directory and file structure. You can peek under the covers by either listing the files in a Terminal session with ls -laR /Applications/CodeRunner.app , or by right-clicking on CodeRunner.app in Finder and choosing "View Package Contents" from the menu.

The actual executable can be found in the Contents/MacOS directory, so the correct setting for the EDITOR variable should be:

EDITOR="/Applications/CodeRunner.app/Contents/MacOS/CodeRunner"

However, I tested CodeRunner 2.3 with the MongoDB 3.6.3 shell and it doesn't work as expected as an editor for the mongo shell.

Setting the EDITOR variable and running edit foo in the mongo shell launches CodeRunner with a temporary file with the contents of foo (so far, so good). Unfortunately, saving this file or closing the tab in CodeRunner does not return control to the mongo shell. I found I have to quit the CodeRunner app in order to have edited results returned and resume my mongo shell session.

If your goal is to use a GUI editor for JavaScript functions in the shell, one approach would be to save your JavaScript code in a file and use the load() command to run this in the mongo shell after saving in your preferred editor. Alternatively you could look into MongoDB management tools with code editors (there are quite a few, open source and otherwise). DbKoda is one such example which is cross-platform and open source.

If you need to work with data or query results but do not need any custom functions, I would recommend using a data management UI such as MongoDB Compass .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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