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

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. Brought to you in partnership with Lightbend.

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?




Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.

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