Need to use double quotes, ", not “ or ” or ‘ or ’ or '
Need to quote booleans.
Though looks like unquoted booleans is part of the spec, so idk if it’s supported.
Double quotes still the standard, double checked.
https://www.json.org/json-en.html
Edit: saying it’s valid JavaScript and not valid json just makes it even weirder.
That means mongodb forces you to parse the json, to send to it as a JavaScript object, which it then dumps to bson, to send., instead of just having the query in a file you can read and send without intermediate parsing.
Well your "huge mongo fan" was not a "huge mongo expert" then, or they'd have had no issues churning out queries and aggregate pipelines into a text editor.
(Source: me, someone who has worked with mongodb and, even better, knows how to use it too)
For one to one relations? Sure, for one to many and many to many? Absolute nightmare returned data that you have to deal with.
Not that MongoDB's aggregation pipeline with multiple (or nested) lookups is intuitive or easy to use, but it is powerful enough if you know how to use it and returns fully usable dataset without further processing on the application-side.
That depends on your requirements doesn't it? For instance placing the same product under multiple categories, the select query for this in SQL would fetch you a separate row for all the categories the product is in, and you'd process this in your application, whereas in MongoDB for instance you'd get the result instantly.
Creating a separate table for the many-to-many relation is the table's normalization, when querying it would look something like this (assuming you want all the category data):
SELECT * FROM products p LEFT JOIN products_categories pc ON p.Product_ID = pc.ProductID LEFT JOIN categories c ON c.Category_ID = pc.Category_ID
Product_ID
Product
Category_ID
Category
1
TV
1
Electronics
1
TV
2
Home Appliances
2
Fridge
2
Home Appliances
This is where you have to aggregate and process the different rows application side, whereas a MongoDB query for the same concept would require only 2 tables (products table with the category IDs array field, and categories table):
View all comments
Show parent comment
291
u/rastaman1994 Oct 18 '24
I'm indifferent in this debate, but everyone I work with can do this for regular find/update/delete operations.
What were you asking anyway? Aggregation pipelines do become complex.