I am evaluating the possibility to start working with MongoDB using NodeJS, however, I am formatted to think in SQL and not in noSQL, I find myself with the following dilemma which takes a day chewing and all post / tutorials They seem to ignore this part so: either I do not understand or mongoDB does not apply to my case.
I have the following example case (only for the purposes of this question):
If I need to save a sale in MySQL, I would do it in tables:
Cabecera de la venta
ID_VENTA | NUMERO | ID_CLIENTE | TOTAL
1 | 001 | 20 | 200
Detalle de la venta
ID_VENTA | ID_PRODUCTO | PRECIO_UNITARIO | CANTIDAD | TOTAL
1 | 5 | 15 | 4 | 60
1 | 78 | 14 | 10 | 140
Productos
ID_PRODUCTO | PRODUCTO |
5 | CAMISA |
78 | ZAPATOS |
Clientes
ID_CLIENTE | NOMBRE |
20 | JUAN PEREZ |
150 | ALBERTO RUIZ |
The same thing in MondoDB would be a single document:
{
"NUMERO" : "1",
"TOTAL" : "200",
"CLIENTE" : "JUAN PEREZ",
"DETALLE" : [
{"PRODUCTO" : "CAMISA", "PRECIO_UNITARIO":"15", "CANTIDAD":"4"},
{"PRODUCTO" : "ZAPATOS", "PRECIO_UNITARIO":"14", "CANTIDAD":"10"},
],
}
Now, we could have documents for each client / products, but they would only be in the form of a dictionary, since they would not be directly related to the detail of the sale.
1.Para los Productos
[
{"PRODUCTO" : "ZAPATOS"},
{"PRODUCTO" : "CAMISA"},
]
2.Para los Clientes
[
{"CLIENTE" : "JUAWN PEREZ"},
{"CLIENTE" : "ALBERTO RUIZ"},
]
And we omitted IDs, with which I have the following doubts:
Or any other case of report, imagine if I want to obtain the sales grouped by product, I would get the sales of 4 days are SAPATOS and the rest with SHOES.
I understand that being noSQL does not accept JOIN, however I see that there are "ways" to perform JOINs, maybe looking for the IDs (assuming the case that emulates the relational tables) individually after bringing the header table .
I hope I have been clear enough and I know that more than one will have gone through this problem and I appreciate the hand they can give me to resolve it.