![]() Require Bson objects, and JavaScript will generate only Map objects.įor example db.m圜ollection.find() will result in a call of db.m圜ollection.find(Bson bson) with a Map instead of Bson, which will throw an error. The reason for this is that most of the methods The collection objects are wrapped as well into WrappedMongoCollection. This make possible to do ´db.m圜ollection´ - otherwise it would work only db.getCollection('m圜ollection') The WrappedMongoDatabase is a wrapper around the native MongoDatabase object, with support for Collections as native member variables. The engine receives also an object 'db':new WrappedMongoDatabase(). In the MongoPreparedStatement we start a Rhino JavaScript engine, and pass this query to the engine. The driver implements a PreparedStatement where native MongoDb queries can be passed. We are looking forward to improve this and make possible to execute all MongoDb native queries via JDBC. ResultSet rs = statement.executeQuery( query ) Īny contributions to this project are welcome. Statement statement = con.createStatement() String query = "db.sampleCollection().find()" OTHER URL (SAME AS FOR MONGODB NATIVE DRIVER): mongodb://,:2500/?replicaSet=test&connectTimeoutMS=300000 Properties.put("password", "somepassword" ) Ĭonnection con = DriverManager.getConnection("jdbc:mongodb://host1:9160/keyspace1", properties) Properties properties = new Properties() Unpack and include all jars in your classpath. Download JDBC Driver Binary Distributionĭownload the driver from the DbSchema website. The collection fields can be sorted by adding sort=true in the URL.Ĭode modifications allowed only to the current repository as pull requests The number of scanned documents can be set in the URL using the parameter scan=. Scanning random documents from each collection. We presume that collections are storing similar documents, so we 'deduce' a virtual schema by To be able to execute native MongoDb queries we embedded an Rhino JavaScript engine inside the driver.Įach time you execute a query we parse and run it as JavaScript with Rhino.Ĭalling methods from the DatabaseMetaData.getTables(), getColumns(), etc., the driver willĭeduce a logical structure of the database. This because the first document in the result may have less keys as the next records. If expand is set the driver will read ahead a number of rows in order to create a correct ResultSetMetaData. Use resultSet.getObject(1) to get this object.Īdding the parameter expand=true in the URL will create a column in the result set for each key in the result document. The driver returns by default a ResultSet with a single Object. Therefore, the JDBC URL is the same as MongoDb URL. The driver is using the native MongoDb Java driver to connect and execute queries. JDBC driver capable to execute native MongoDb queries, similar with Mongo Shell. The driver is provided by DbSchema - MongoDb Diagram Designer for everybody who needs an MongoDb JDBC driver. MongoDb JDBC Driver | DbSchema MongoDB Designer
0 Comments
Leave a Reply. |