問題描述
Windows 是否有任何 mongo shell 擴展? (Is there any mongo shell extensions for windows?)
I've found the mongo‑hacker project, but it doesn't support Windows, so I am wondering does anybody know similar one?
‑‑‑‑‑
參考解法
方法 1:
Honestly I can't find restrictions which are connected with Windows, except:
- *nix‑specific commands in
Makefile
andREADME
- http://docs.mongodb.org/manual/release‑notes/2.2/#windows‑specific‑changes (which states, that WinXP isn't supported for 2.2)
- checking
_isWindows()
inmongo_hacker.js
I've been using for a quite long time Mongo DB in *nix and Windows, and the only difference which I have faced is an absence of ‑‑fork
param in Win version.
So what I would try to do (in Win7 f.e.):
- remove
_isWindows()
line - start mongo terminal on some test DB with
‑‑shell
command, just for playing with this
mongo localhost/test ‑‑shell mongo_hacker_custom.js
Then, if everything is working properly, you can fill ~/.mongorc.js
with mongo_hacker_custom.js
content, without creating of symbolic link (BTW, starting with Vista Windows also supports them already, so symbolic link is also suitable).
P.S. Now I can't try this solution, will check in a few hours suggested solution by myself.
UPD: yeap, it seems to be working just fine on my Windows 7 + MongoDB 2.2.1
方法 2:
mongo‑hacker does work on windows but a little work is required : ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ 1) Make your own mongo configuration file (.mongorc.js) ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ This is located in your documents : %USERPROFILE%\.mongorc.js eg. C:\Users\Olivier\.mongorc.js A) Make all files from mongo‑hacker into one big JS file. ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ A.1. If you have cygwin (or some unix emulation tools) : There might be a better way to achieve this but this will work. Once the .zip file is unzipped, and your are in \mongo‑hacker‑master\hacks find ./ ‑type f ‑name "*.js" | xargs cat > .mongorc.js You can then move this file to your documents. A.2. Else : Or, if more convenient here is my version (v 0.0.4 at the time of writting) : Download : .mongorc.js example for windows And copy this file in your documents. ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ 2) Get the coloring working : ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ A) Download : ansicon ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ This processes ANSI escape sequences for Windows console programs. B) Add this to your windows path ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ To get there : > Click on start menu > Right click on computer > Properties > Advanced system settings > Environment variables Once there, in the 2nd section (system variables) : You will see variable : Path > Click on its value, and add the path to the ansicon.exe program, eg : C:\Program Files\ansicon\x64; C) Then ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ You can now prefix your command with ansicon to get the coloring working : eg : $ ansicon.exe mongodb
‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ 3) Get a proper shell ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑ The out of the box windows shell (cmd.exe), being what it's, I'd really recommand that you get a proper shell. For example : console is a very nice program. I hope this helps !
方法 3:
The only reason for that line is due to the ANSI colouring not working in the windows terminal/cmd window (the Esc
chars get output rather than interpreted).
Disable the colouring (there are several methods but emptying the 'constants' or NOPing the lower level call that everything ends up calling both work) and remove the check for windows to be able to use it.
Your other alternative is to run it under screen
as the output colours at least work there (but not the prompt colours for some reason).
(by Restuta、n1ckolas、OlivierLarue、ChrisF)