资源说明:MongoDB Shell built on the Rhino JavaScript Engine for Java.
Horn of Mongo ============= [![Build Status](https://travis-ci.org/nlloyd/horn-of-mongo.png?branch=master)](https://travis-ci.org/nlloyd/horn-of-mongo) MongoDB Shell built on the Rhino JavaScript Engine for Java. Currently tested against mongodb release: 2.4.6 ## Usage All actions within the a mongodb-enabled Rhino `Context` happen through `MongoRuntime`. Before anything can happen, however, you need to first create a `MongoScope` to work from using static methods within `MongoRuntime`. After you have a `MongoScope` you can execute just about any mongodb script you want from the convenient `MongoRuntime.call(..)` method! There are two ways to create a `MongoScope`. The first will create an environment without the `db` global variable. The second will create a connected client for you but expects more information (ex. hostname(s) and a database name in the form of a `MongoClientURI`). #### Disconnected MongoScope ```java import org.github.nlloyd.hornofmongo.MongoRuntime; import org.github.nlloyd.hornofmongo.MongoScope; ... MongoScope myMongoScope = MongoRuntime.createMongoScope(); // then to create the 'db' global variable and open a connection to a mongod instance... MongoRuntime.call(new MongoScriptAction(myMongoScope, "connect", "db = connect('someHost:27017/someDb',myUserName,myPassword);")); // or if no authentication is required... MongoRuntime.call(new MongoScriptAction(myMongoScope, "connect", "db = connect('someHost:27017/someDb',null,null);")); ... MongoRuntime.call(new MongoScriptAction(myMongoScope, "your special script, or a Reader instead of this string")); ``` #### Connected MongoScope ```java import org.github.nlloyd.hornofmongo.MongoRuntime; import org.github.nlloyd.hornofmongo.MongoScope; ... MongoScope myMongoScope = MongoRuntime.createMongoScope(new MongoClientURI("mongodb://localhost/test"), true, true); ... MongoRuntime.call(new MongoScriptAction(myMongoScope, "your special script, or a Reader instead of this string")); ``` After that you can feed scripts as strings or `Reader` instances through the MongoRuntime.call(..) method wrapped in `MongoScriptAction` objects. ### Additional Configuration Options The `MongoScope` instance can be configured with two additional flags that can closely replicate the behavior observed in the official mongo shell client. `myMongoScope.setUseMongoShellWriteConcern(true)` will configure the wrapped mongo client to use the WriteConcern used by the official mongo shell client which is send-and-forget. `myMongoScope.setMimicShellExceptionBehavior(true)` will cause the Horn of Mongo environment to intercept some exception types from the wrapped mongo client and instead of throwing an exception in the mongodb-enabled Rhino environment will print an error to stdout. Which exceptions are intercepted have been determined based on the behavior of the official mongo shell client. The functionality of this project has been evaluated using the official JavaScript tests from the mongodb project. Most of the tests are used with some exceptions indicated below. ## Known Limitations The following official mongodb JavaScript tests have been excluded. Tests that are excluded due to unsupported functionality simply reference the current lack of interest in implementing the support in this project and have nothing to do with the mongo java driver project. * **_run_program1.js_** is excluded due to the currently unsupported runProgram() function. * **_mr_noscripting.js_** and logpath.js are excluded due to the currently unsupported MongoRunner js class. * **_evalf.js_** is excluded due to a locking issue that has yet to be resolved, however the complexity of the test scenario makes this a safe-to-exclude for now. * **_indexOtherNamespace.js_** excluded because I can't for the life of me get the failure scenario to actually fail using the mongo java driver :-( * **_memory.js_** is excluded because it is testing the mongod rather than the client api behavior (and it takes a while to run on slower machines). This test does actually pass, however. * **_remove_justone.js_** excluded until the mongo java driver supports that feature: https://jira.mongodb.org/browse/JAVA-759 * **_basicc.js_**, **_bench_test1.js_** **_bench_test2.js_**, **_bench_test3.js_** **_connections_opened.js_**, **_count8.js_** **_coveredIndex3.js_**, **_currentop.js_** **_cursora.js_**, **_distinct3.js_** **_drop2.js_**, **_evalc.js_** **_evald.js_**, **_explain3.js_** **_group7.js_**, **_index12.js_** **_killop.js_**, **_loadserverscripts.js_** **_logpath.js_**, **_mr_drop.js_** **_mr_killop.js_**, **_orm.js_** **_orn.js_**, **_queryoptimizer3.js_** **_queryoptimizer5.js_**, **_remove9.js_** **_removeb.js_**, **_removec.js_** **_shellkillop.js_**, **_shellstartparallel.js_** **_shellspawn.js_**, and **_updatef.js_** are excluded because they rely on the following functions `startMongoProgramNoConnect()` and `startParallelShell()` which there are no plans to implement ## Changelog ### v1.3 Updated and tested against mongodb version 2.4.6 Upgraded to use mongo-java-driver 2.11.3 Applied patch from [AquaFold](http://www.aquafold.com) that stores a reference to the DB instance after each API query for later getLastError() checks ### v1.2.2 Added CurrentDirectoryHandler interface as a mechanism similar to PrintHandler, QuitHandler, etc. for providing custom handling of cwd operations as well as path resolution. Additional minor changes provided by [AquaFold](http://www.aquafold.com) applied. ### v1.2.1 Fixed minor classloader issue. ### v1.2 Updated and tested against mongodb version 2.4.5 Upgraded to use mongo-java-driver 2.11.2 **_fts_blogwild.js_** and **_fts_mix.js_** included in test suite, https://jira.mongodb.org/browse/JAVA-814 resolved in latest mongo-java-driver release Improved exception handling in several adaptor class constructors ### v1.1 Updated and tested against mongodb version 2.4.4 ### v1.0 First release! Highly compatible release with mongodb version 2.4.3 (see Known Limitations). ## Roadmap [Planned Milestones](https://github.com/nlloyd/horn-of-mongo/issues/milestones)
[Issues](https://github.com/nlloyd/horn-of-mongo/issues?labels=&milestone=&page=1&state=open) ## Support Have a feature idea that you want to discuss? [Bring it up here](https://groups.google.com/forum/?fromgroups#!forum/horn-of-mongo) Have a question about a feature? [Bring it up here](https://groups.google.com/forum/?fromgroups#!forum/horn-of-mongo) Have a bug you want to report? [Bring it up here](https://groups.google.com/forum/#!forum/horn-of-mongo) Want to hear about the latest that is happening on this project? [Read about it here!](https://groups.google.com/forum/?fromgroups#!forum/horn-of-mongo) ## Contributors AquaFold, patch contributors, horn-of-mongo is the core engine behind the MongoDB features in their upcoming release.
Show your support by donating! ## License All of Horn of Mongo is licensed under the MIT license. Copyright (c) 2012 Nick Lloyd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。