|
Project Information
|
This project aims to eventually provide full integration between the Rhino JavaScript engine for the JVM and MongoDB. It uses the Java driver for MongoDB, included in the distribution. Original code by Tal Liron. Contributions from Jamie McCrindle. Stay Native with BSONWe allow conversion to/from native JavaScript objects and MongoDB's BSON. We support JavaScript Date objects, RegExp objects, BSON object IDs, binaries and references. This allows you to use MongoDB API and documents directly from Rhino without textual parsing of JSON. High-performance JSONIncluded is excellent support for JSON using the JSON Rhino library, which performs much better than the JavaScript JSON API. More importantly, JSON conversion fully supports MongoDB's extended JSON. Specifically, we support $oid, $ref, $date, $binary and $regex notations. We've also extended the already-extended JSON by adding a $long notation: this allows transcribing JVM Long instances as strings in JavaScript (which internally uses double primitives) allowing for transfer via JSON without loss of precision. InstallationMake sure com.mongodb.jar and com.mongodb.rhino.jar are in your JVM classpath. ExamplesSee MongoVision for a complete example application. Simple example: importClass(com.mongodb.Mongo, com.mongodb.rhino.BSON)
JSON = com.mongodb.rhino.JSON
var connection = new Mongo()
var db = connection.getDB('mydatabase')
var collection = db.getCollection('mycollection')
var doc = {name: 'hello'}
collection.insert(BSON.to(doc))
var query = {name: 'hello'}
var update = {$push: {anArray: 'aValue'}}
collection.update(BSON.to(query), BSON.to(update), false, false)
var query = {name: /he(.*)/i}
var doc = BSON.from(collection.findOne(BSON.to(query)))
java.lang.System.out.println(JSON.to(doc))
|