Code Monkey home page Code Monkey logo

horn-of-mongo's Introduction

Horn of Mongo

Build Status

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

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

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 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 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
Issues

Support

Have a feature idea that you want to discuss? Bring it up here Have a question about a feature? Bring it up here Have a bug you want to report? Bring it up here Want to hear about the latest that is happening on this project? Read about it here!

Contributors

AquaFold, patch contributors, horn-of-mongo is the core engine behind the MongoDB features in their upcoming release.


Show your support by donating!

Click here to lend your support to: Horn of Mongo and make a donation at www.pledgie.com !

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.

horn-of-mongo's People

Contributors

nlloyd avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.