Of curiosity, I would like to know, how anyone would implement a custom mongo shell in .Net. allowing the user to do the exact same things as you can in the mongo shell, but implemented in .Net with the option of enhancing the user experience.
I have found this thread which tells me, that I cannot use the official 10gen driver to archieve this: Using MongoDB shell commands on MongoDB 10Gen's driver
What is the appropriate way of doing this? I guess the ultimate custom solution would be to convert the source code for the mongo shell into .Net by hand?
Any suggestions are very much appreciated as I have been googling for answers in quite some time. Thankyou in advance!
The best answer to your request to “do the exact same things as you can in the mongo shell” depends on what you are thinking of as “exact same things”.
At the lowest level, the mongo shell just sends messages using the documented “wire protocol”, which is a bit of wrapping around BSON data, the documented binary version/extension of JSON. So, at a low level (by sending messages over TCP/IP) you can do anything you want.
At a slightly higher level, the mongo shell includes a JavaScript “engine”, which in currently released versions is SpiderMonkey version 1.7 from the Mozilla Foundation, also open source. A future version will use Google’s V8 JavaScript engine, again open source and available for download. The shell provides some native code functions for those engines to use: see engine_spidermonkey.cpp and engine_v8.cpp in the MongoDB source code.
At a still higher level, the shell includes some “helper functions” written in JavaScript that simplify typing some commands. You can see these functions from the shell’s prompt by typing the name of a function call and leaving off the parentheses: typing “sleep(500)” will sleep for 500 milliseconds, typing “sleep” will show that “sleep” calls “nativeHelper.apply(sleep_, arguments)”. All of these helper functions are in .js files in the “shell” directory in the MongoDB source code, which you can download.
Beyond that, there is a command line loop that provides command line editing and recall, code for processing arguments on the invoking command line and code to read and write BSON-formatted data for communication with the server, very similar to what the C# driver provides.
So, you can use any of this code that is helpful to you or write similar or different code yourself. There isn’t really any magic hidden away, it’s all open source.
If you know what you want to accomplish and get stuck on the details of how to do something, ask your specific question and hopefully you’ll get less general answers than this one.