8

Is there any library where i can access mongodb by using sql like syntax.

Example

use db select * from table1 insert into table1 values (a,b,c) delete from table select a,b,count(*) from table1 group by a,b select a.field1,b.field2 from a,b where a.id=b.id 

Thanks Raman

3
  • 3
    why would you want to do that? Commented Apr 10, 2012 at 11:35
  • 1
    if you want to use sql, do not use Mongodb but use an RDBMS Commented Apr 10, 2012 at 12:28
  • 2
    Sometimes, when you want to switch from RDBMS to NoSql, you face Legacy problems, and to simplify that process you wish to have something that will acts like proxy, accepting SQL and mapping it NoSQL functions. Commented Oct 22, 2012 at 9:51

8 Answers 8

7

The learning curve is small only if you are doing extremely simple sql queries. If the extent of your SQL querying is "select * from X", then MongoDB looks like a brilliant idea to cut through all the too-complicated SQL. But if you need to perform left outer joins, test for null, check for ranges, subselects, grouping and summation, then you will soon end up with a round concave dent in your desk after being moved to Mongo. The sick punchline is that half the time, the thing you are trying to do can't be done in the Mongo interface. Mongo represents a bold new world where instead of databases doing things like aggregation and query optimization, it just stores data and all the magic is done by retrieving everything, slowly, storing it in app memory, and doing all that stuff in code instead.

Sign up to request clarification or add additional context in comments.

3 Comments

Though your advice might be very valuable, you didn't answer the question; please consider to write this kind of input as a comment.
No this is a great answer still true even43 years later. Mongo is terrible for reporting.
Great answer! Exactly the type of information someone brought to this question is looking for.
6

YES!

A company called UnityJDBC makes a JDBC driver for mongodb. Unlike the mongo java driver, this JDBC driver allows you to run SQL queries against MongoDB and the driver is supported by any Java appliaction that uses JDBC.

to download this driver go to...

http://www.unityjdbc.com/mongojdbc/mongo_jdbc.php

Its free to download too!

hope this helps

Comments

2

MoSQL might satisfy your needs. It'll require you to run a new PostgreSQL instance but from there you can query your entire Mongo dataset with SQL.

"MoSQL imports the contents of your MongoDB database cluster into a PostgreSQL instance, using an oplog tailer to keep the SQL mirror live up-to-date. This lets you run production services against a MongoDB database, and then run offline analytics or reporting using the full power of SQL."

Comments

1

Have a look at this recent project: http://www.mongosql.com/. I've been looking at it over the last few weeks and it looks very promising.

For those of you who have questioned the usefulness of SQL against MongoDB, consider the large number of not-very-technical users in many organizations, like business analysts, who may know SQL, but don't want to make the leap to JavaScript and JSON. Tools like mongoSQL can help push the adoption of MongoDB in an organization.

Comments

1

There are a few solutions out there, but nearly all of them fail to truly represent the MongoDB data model in a way that the "relationally" minded ODBC/JDBC applications and users desire/require. A recent commercial product was released that addresses these challenges

ODBC: http://www.progress.com/products/datadirect-connect/odbc-drivers/data-sources/mongodb

JDBC: http://www.progress.com/products/datadirect-connect/jdbc-drivers/data-sources/mongodb

To address the need for ODBC/JDBC (SQL) access...While there are strong arguments for writing new applications using Mongo's clients, there is still a strong need in the marketplace for quality ODBC/JDBC and SQL based access to MongoDB. This need largely arises from all the reporting, analytic, and BI applications that rely on ODBC/JDBC connectivity and do not offer native integration with MongoDB.

1 Comment

I have tried progress jdbc/mongodb driver with "group by -having" query. But the performance was terrible compared to the MongoDB native aggregation framework.
1

Free NoSQL Viewer supports conversion of SQL queries to MongoDB shell syntax. Furthermore, in SQL Viewer you can even use SQL SELECT statements to query MongoDB collections data without knowing MongoDB query syntax. Check out NoSQL Viewer here www.spviewer.com/nosqlviewer.html

Comments

-2

Mongodb and its current driver do not support direct SQL like syntax. However, all operations are easily doable with the driver specific operations. Here is a brief mapping of mongodb operations to corresponding SQL like query :

http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart

Comments

-2

There are a couple projects underway to emulate a SQL interface for MongoDB. While they provide a familiar interface, in general they should be avoided. They operate on a fundamentally flawed premise in that they parse strings and translate them into method calls.

Once you work with MongoDB you will find the approach of using classes and methods a much more accessible interface as it works exactly like all other parts of your application. Yes there is a small learning curve as you first start, but for the most part, the interface in MongoDB works how you would expect it to.

1 Comment

Systems that "parse strings and translate them into method calls" are most definitely not "a fundamentally flawed premise". Every console and script-based programming language does this. Run-time evaluation is incredibly powerful - is it truly any different compiling MapReduce instructions in C++ compared to having them generated from a script on the fly?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.