3 ms·
JSON is used as a query language because it's fast, easy to parse and easy to generate dynamically. If you have a query interface for users, SQL is probably a b
by samarudge 14y ago
JSON is used as a query language because it's fast, easy to parse and easy to generate dynamically. If you have a query interface for users, SQL is probably a better choice, but Mongo chose JSON for performance reasons.
If you don't like dealing with it directly, use something like MongoEngine so you're not working with the raw queries, or if having readable, easy to understand queries is important, use a SQL database.
Everything is a compromise, with Mongo's query language you're sacrificing readability for performance.
( This is not a comparison of a SQL database to Mongo, just the time it takes for a SQL engine to parse the query into an execution plan )
- marshray 14y ago> JSON is used as a query language Maybe a little more accurate to say JSON is used as a base layer for the query language. JSON is "JavaScript Object Notation". But the "meaning" of the query is in the objects being denoted, not the notation used to represent them as text. So comparing Mongo's use of JSON to SQL is apples-to-oranges. We could encode SQL as JSON too: {"query": "SELECT * FROM things;"} or {"query": [ {"SELECT": "*"}, {"FROM": "things"} ] } without affecting the expressive power of the SQL language one bit.
- sm_sohan 14y agoThis doesn't have to be this way. The underlying machine friendly API can be hidden under a human friendly API abstraction.