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

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

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?




Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

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