Live data from Hacker News

MongoDB Is Abusing JSON

smsohan.com

11–20 of 61 posts

Re: MongoDB Is Abusing JSON

#11

JSON is used as a query language because it's fast, easy to parse and easy to generate dynamically. If you have a query interface for users, SQL is probably a better choice, but Mongo chose JSON for performance reasons. If you don't like dealing with it directly, use something like MongoEngine so you're not working with the raw queries, or if having readable, easy to understand queries is important, use a SQL databas…

> JSON is used as a query language

Maybe a little more accurate to say JSON is used as a base layer for the query language.

JSON is "JavaScript Object Notation". But the "meaning" of the query is in the objects being denoted, not the notation used to represent them as text. So comparing Mongo's use of JSON to SQL is apples-to-oranges.

We could encode SQL as JSON too:

    {"query": "SELECT * FROM things;"}
or

    {"query": [
        {"SELECT": "*"},
        {"FROM": "things"} ] }
without affecting the expressive power of the SQL language one bit.

Re: MongoDB Is Abusing JSON

#12

You picked an ugly mongo query, and there are many. You compared it to a concise SQL query, and there are many that are not. MongoDB's limit(x) and skip(y) are a shitload nicer than most of Microsoft's ideas about pagination. It was only in SQL Server 2012 that they came up with "OFFSET" instead of "google it".... http://stackoverflow.com/questions/2244322/how-to-do-paginat...

I literally just ran into the same issue with SQL Server. Since we're running an older version, I was very confused when I found the alternative to MySQL's "LIMIT"-- it wasn't pretty.

Re: MongoDB Is Abusing JSON

#14

You picked an ugly mongo query, and there are many. You compared it to a concise SQL query, and there are many that are not. MongoDB's limit(x) and skip(y) are a shitload nicer than most of Microsoft's ideas about pagination. It was only in SQL Server 2012 that they came up with "OFFSET" instead of "google it".... http://stackoverflow.com/questions/2244322/how-to-do-paginat...

I literally just ran into the same issue with SQL Server. Since we're running an older version, I was very confused when I found the alternative to MySQL's "LIMIT"-- it wasn't pretty.

I like how they timed something everyone has wanted for like a million years with the switch to per-core pricing lol.

Re: MongoDB Is Abusing JSON

#15
post #3

There is always http://querymongo.com/ which will convert SQL to a MongoDB query.

I actually dislike this tool a fair bit, because it gets people to continue thinking of Mongo as "Mysql plus WEB SCALE" or whatever. It's a totally different database and doesn't do well with highly-normalized relational-style data, and the idea of an "automated converter" seems to reinforce the idea that it's just a drop in for MySQL that automatically solves all your scaling woes, when that's just utterly and completely false.

Trying to shove a MySQL square into the Mongo triangle just isn't going to work out that well.

Re: MongoDB Is Abusing JSON

#16
I've been through the hassle of programatically piecing together complex SQL queries, and I'd far rather be able to just put together hashes that represent my query.

SQL was originally designed so that people who were savvy but not necessarily developers were able to query databases, but I can't think of the last time my boss would have wanted to run some random query against our production database.

Re: MongoDB Is Abusing JSON

#17
post #2

TL;DR: JSON sucks for representing queries.

It's not JSON, but rather that MongoDB's query language sucks. I'm not entirely sure how to fix it - perhaps make it slightly more verbose and meaningful?

Probably there are better ways to express a query in JSON compared to how MongoDB does it, but I'd take a step back and ask whether a nested map is the best approach to think about it.

Re: MongoDB Is Abusing JSON

#18

MongoDB is a NoSQL-type database, so it wouldn't make sense to have a SQL query interface... I think they did a good job with the API for not using SQL. Plus, the API isn't really abusing JSON. It isn't pretty, but it's not abuse.

People seem to be confusing "NoSQL" and "non-relational". Mongo happens to be both, but there's nothing fundamental that puts the two together. You may not get the full capabilities of SQL with non-relational data (JOINs, etc), but there's no reason that non-relational data stores couldn't parse normal SQL and execute the appropriate queries.

You can make a relational database that doesn't support the SQL syntax, and you can use SQL syntax to interact with schemaless data (for added fun, try throwing JSON in a mysql/postgres text field).

I'd agree with the article saying this is an abuse of JSON, though. It's a format to represent data; more accurately, potentially-nested key:value stores, arrays, and scalar types. A query is not data (unless you're one of those "my database has a 'queries' table" types)

Re: MongoDB Is Abusing JSON

#20
post #17

Earlier quoted context omitted.

It's not JSON, but rather that MongoDB's query language sucks. I'm not entirely sure how to fix it - perhaps make it slightly more verbose and meaningful?

Probably there are better ways to express a query in JSON compared to how MongoDB does it, but I'd take a step back and ask whether a nested map is the best approach to think about it.

I actually prefer Mongo's query language to SQL, because it makes sense to my programmer brain. It's basically "push operand, push values", which makes a ton of sense. It's just plain old Polish notation.
Post reply on HN