Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MongoDB Is Abusing JSON!

DZone's Guide to

MongoDB Is Abusing JSON!

· Java Zone ·
Free Resource

Delivering modern software? Atomist automates your software delivery experience.

I think the MongoDB API is abusing JSON in a really bad way. JSON is probably a good format for storing the documents in MongoDB, but using JSON for its weird API is simply a terrible idea. Here’s an example from the SQL to Aggregation Framework Mapping Chart:

  db.orders.aggregate( [
     { $group: { _id: { cust_id: "$cust_id",
                        ord_date: "$ord_date" },
                 total: { $sum: "$price" } } },
     { $match: { total: { $gt: 250 } } }
  ] )

I think the the UI of this query is distasteful at the best. Here’s an SQL example of the same information:

  SELECT cust_id,
         ord_date,
         SUM(price) AS total
  FROM orders
  GROUP BY cust_id, ord_date
  HAVING total > 250

I find this SQL example to be several orders of magnitude more readable than the JSON one. The JSON query in this example is full of hacks. Every time I see a “$” sign, I’m totally confused about what it means. For example, consider this fragment – total: { $sum: “$price” } – and compare it to SUM(price) AS total.

I think MongoDB has its strengths. But for haven’s sake, if they can’t find anything better, they should leave this JSON ugliness in favor of SQL for the query interface to MongoDB. What do you think?




Start automating your delivery right there on your own laptop, today! Get the open source Atomist Software Delivery Machine.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}