Standalone JDBC driver for MongoDB
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src rs.getString(-100) returns the raw document now Jan 22, 2016
.gitignore initial code contribution Dec 18, 2015
README.md Update README.md Jan 29, 2016
pom.xml pom update Jan 22, 2016

README.md

mongo-jdbc

JDBC channel for MongoDB. While this driver mostly adheres to the JDBC ways of connections, statements and resultsets, note that this driver does not translate to/from SQL. It uses Mongo's query format instead. You have the option to choose between browsing result sets using the JDBC API or directly get the underlying document and operate on it.

Example:

MongodbConnection conn = new MongodbConnection("jdbc:mongodb://localhost/mydb", null);
try {
	Statement st = conn.createStatement();
	ResultSet rs = st.executeQuery("{ find: \"testCollection\",filter: {$text:{$search:\"name\"}} }");
	while(rs.next()){
		System.out.println("get string by column name: " + rs.getString("name"));
		System.out.println("get string by column index: " + rs.getString(2));
		System.out.println("raw document: " + rs.getString(-100));
	}
	rs.close();
	st.close();
} catch (SQLException e) {
	e.printStackTrace();
} finally {
	try{
		conn.close();
	} catch(SQLException sqlEx){
		sqlEx.printStackTrace();
	}
}

Tips, tricks, fancy features

Get the raw Document from ResultSet iteration as JSON

String doc = rs.getObject(-100);

Specify a collection to query

stmt.executeQuery(‘{find:"testCollection"}’);