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

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

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?




Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Published at DZone with permission of S M Sohan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}