TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: SQL to Mongo Query Translator

62 pointsby robertjmooreover 12 years ago

15 comments

polskibusover 12 years ago
I don't have any experience with MongoDB, but the example put me off using it completely. The MySQL query is concise and brief, the MongoDB equivalent is bloated. Only after several seconds I was able to deduce that the MongoDB query probably does something more than MySQL query. Can you please make the examples more comparable? Or did I misunderstand the MongonDB and it actually is so bloated by design? I believe it is not your goal to discourage people from MongoDB , if so, better not do it unintentionally.
评论 #4910171 未加载
评论 #4914056 未加载
评论 #4910155 未加载
评论 #4910192 未加载
ritover 12 years ago
The default query already filled in is translating to the use of a Group function, which is a very bad idea. While not deprecated per se, its use is discouraged.<p>Group <i>does not function in Sharding mode at all</i>, it also takes a lock on the JavaScript interpreter making it non-parallelizable.<p>Map/Reduce is somewhat better in that it is shardable, and with V8 likely in the next stable release, will have better parallelization prospects.<p>Ideally, you should be using the new Aggregation Framework to do this kind of work: <a href="http://docs.mongodb.org/manual/applications/aggregation/" rel="nofollow">http://docs.mongodb.org/manual/applications/aggregation/</a><p>(EDIT) To clarify - Aggregation is ideal because its implementation is 100% in C++, meaning there are no JavaScript interpreter locks necessary to run it, so it is parallelizable. Additionally, one of the biggest overhead costs to MapReduce and Group in MongoDB is the translation back and forth between BSON (the native format MongoDB uses for data, or rather the C++ representations thereof) and JavaScript types. Aggregation not utilizing JavaScript eliminates this overhead and manipulates the database' internal types directly.
评论 #4910130 未加载
评论 #4911079 未加载
评论 #4914462 未加载
redlerover 12 years ago
The example would be much clearer as an aggregation query. Roughly:<p><pre><code> db.demo.aggregate([ { $match: { score: { $gt: 0 }, person: { $in: ["bob","jake"] }}}, { $group: { _id: "person", sumscore: { $sum: "$score" }, avgscore: { $avg: "$score" }, minscore: { $min: "$score" }, maxscore: { $max: "$score" }, count: { $sum: 1 }}} ]);</code></pre>
gryover 12 years ago
I've also found this diagram incredibly helpful translating from a SQL to map/reduce world.<p><a href="http://rickosborne.org/blog/2010/02/infographic-migrating-from-sql-to-mapreduce-with-mongodb/" rel="nofollow">http://rickosborne.org/blog/2010/02/infographic-migrating-fr...</a>
评论 #4911317 未加载
rmrfrmrfover 12 years ago
I didn't realise that Mongo was so...verbose.
sgtover 12 years ago
Not particularly useful, I tried a simple join and I got this error message:<p>Failure parsing MySQL query: Unable to convert queries based on more than one table
评论 #4910119 未加载
评论 #4910392 未加载
e98cuencover 12 years ago
Very nice! I once thought about doing something like this, but I had some real work to do. Thanks for this resource!<p>This is specially useful because of the verbosity and ugliness of the "JSON" API (much more difficult to get right by hand than SQL) and because I found 0 working GUI tools to work with Mongo in a mac (they all crash at startup or after ~5 seconds of usage in a modern mac).
评论 #4910187 未加载
christkvover 12 years ago
any particular reason you are not mapping to the aggregation framework which is a lot faster ?
评论 #4910002 未加载
rolfvandekrolover 12 years ago
Nice work. Played around with it, and found that<p>SELECT * FROM demo WHERE score &#62; 0 AND person LIKE '%bob%'<p>doesn't work that well. It will need to convert the %bob% thing to a regular expression.
isabreover 12 years ago
Awesome! I haven't played around with NoSQL databases and I always wondered how you would query one. Definitely peaked my interest in the whole movement.
fox91over 12 years ago
I find it pointless. If you want to write SQL queries just use a relational database, if you want to use Mongo learn to use it.
评论 #4911095 未加载
nohaving2over 12 years ago
HAVING clause is being ignored. i.e. try adding<p><pre><code> HAVING SUM(abc) &#62; 1 </code></pre> to the example.
hayksaakianover 12 years ago
Is there one that goes in the other direction?
aioprisanover 12 years ago
are there any plans to open source this?
评论 #4911111 未加载
camusover 12 years ago
map/reduce anyone ? if you are using mongodb like a relational database , then maybe you should just stick to relational databases...
评论 #4911838 未加载