Live data from Hacker News

MongoDB Is Abusing JSON

smsohan.com

21–30 of 61 posts

Re: MongoDB Is Abusing JSON

#21

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.

This is a daily occurrence at some companies

Re: MongoDB Is Abusing JSON

#22
post #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 compl…

You mean SQL not MySQL.

Also that might be one thing it does but it also allows people to transition from SQL queries they know to mongodb queries. It helps the learning process.

Re: MongoDB Is Abusing JSON

#23
I feel the same about the query language of Mongo. The first goal of a query language should be ease of use. With mongo having to type all those extra characters quotes, brakets, square brakets, colons is very annoying. You need to type a lot to get any reasonable output.

Re: MongoDB Is Abusing JSON

#24
Aggregation is absolutely one of Mongo's weaknesses. It's not great at ad-hoc aggregation like MySQL or whatnot is, and the fact that it tends to lend itself to denormalized data makes SQL-style reporting clunky at best.

It does a lot of things better than SQL, too. Consider, for example, the query "Give me a list of all posts with all of these tags, by any of these authors, sorted by post date descending"

    db.posts.find({
      tags: {$all: ["foo", "bar", "baz"]},
      author: {$in: ["Joe", "Jane"]}
    }).sort({post_date: -1})
In SQL, you'd end up with something like:

    SELECT posts.* FROM posts
      INNER JOIN post_tags t1 ON t1.tag = "foo" AND t1.post_id = posts.id
      INNER JOIN post_tags t2 ON t2.tag = "bar" AND t2.post_id = posts.id
      INNER JOIN post_tags t3 ON t3.tag = "baz" AND t3.post_id = posts.id
      WHERE posts.author = "Joe" or post.author = "Jane"
      ORDER BY post_date DESC;
Its strength is denormalization; since you can denormalize entire lists or maps of data into a document, and then index and query on them, you can end up performing queries that would be ridiculously ugly and tedious in SQL.

Re: MongoDB Is Abusing JSON

#25
post #15

Earlier quoted context omitted.

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 compl…

You mean SQL not MySQL. Also that might be one thing it does but it also allows people to transition from SQL queries they know to mongodb queries. It helps the learning process.

No, I mean MySQL. The tool linked is specifically tooled for MySQL queries.

I fully support it as a learning tool, but Mongo's query language isn't all that hard to pick up if you already know how SQL works. Getting stuck into the mindset of "just write relational DB-oriented software and then generate some Mongo queries for it" is an awful practice that is sure to lead to much pain and suffering.

Re: MongoDB Is Abusing JSON

#26

Here's what this query looks like in RethinkDB (also based on JSON documents): r.table('orders') .pluck('cust_id','ord_date','price') .groupBy('cust_id','ord_date', r.sum('price')). .filter(r.row('reduction').gt(250)) We use the hard-coded attribute 'reduction' because groupBy automatically gets compiled to our distributed map-reduce infrastructure. There is currently no as command (though it could easily be simulate…

Most ORMs use dot notation, even for mongo (e.g. mongo engine) to build queries. I think the mongo queries are more true to what it should be since dot notation in most languages implies a function/method is being called and order matters in those cases. Here it's just acting like a query builder that runs with .run().

Under the same effect I'm not a fan of mongo style query({}).limit(count).skip(num) format and usually I move the limit and skip into the initial query.

Re: MongoDB Is Abusing JSON

#27

Here's what this query looks like in RethinkDB (also based on JSON documents): r.table('orders') .pluck('cust_id','ord_date','price') .groupBy('cust_id','ord_date', r.sum('price')). .filter(r.row('reduction').gt(250)) We use the hard-coded attribute 'reduction' because groupBy automatically gets compiled to our distributed map-reduce infrastructure. There is currently no as command (though it could easily be simulate…

The beauty of JSON is you could incredibly easily write such jquery like chained expression to generate the mongo query. JSON is a good ascii representation of structured data thats compact, quite readable and reasonably human editable.

Its not an abuse of JSON to use it as a way of representing queries, but its probably a shame that Mongo haven't provided a better way of generating queries.

Re: MongoDB Is Abusing JSON

#28

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...

There are extremely few modern cases where pagination at the database layer is a good approach.

Re: MongoDB Is Abusing JSON

#29

Here's what this query looks like in RethinkDB (also based on JSON documents): r.table('orders') .pluck('cust_id','ord_date','price') .groupBy('cust_id','ord_date', r.sum('price')). .filter(r.row('reduction').gt(250)) We use the hard-coded attribute 'reduction' because groupBy automatically gets compiled to our distributed map-reduce infrastructure. There is currently no as command (though it could easily be simulate…

What are the main differences between MongoDB and RethinkDB? Things that you hear people care about? I don't use Mongo but I've seen projects that use it. I ask because I want to store & retrieve some analytics.

After seeing the screencast of RethinkDB it seems to me that it's just like Mongo but a much better API and easier handling of sharding and replication. The only con I see of using RethinkDB is that it's very new (so is Mongo...) and probably is little too early for production. Basically I hope not to find worse surprises down the road than I hear of Mongo :P

Re: MongoDB Is Abusing JSON

#30

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.

I am not sure of its origin. But these days you'll find good ORMs that would craft the query for you. My point is, the Mongo API seems to be more of a machine readable API with the $ keys used somewhat in a hacky way.
Post reply on HN