A
A
AlexZeDim2018-12-16 15:41:49
PostgreSQL
AlexZeDim, 2018-12-16 15:41:49

Project architecture: database selection, table relationships, noSQL or SQL?

“How did I develop my pet project, or gentlemen, it seems I screwed up”
Actually, this is not a very common question, but rather an attempt to find advice or cash in on someone else's experience, because I somehow have little of my own.
"Dano" A
small pet project with a back-end written and fully working on:

  • Mongo
  • Express
  • JS
  • Node.js

-
Essence of the project.
The server periodically parses the API of a foreign server and decomposes it into collections / tables, manipulates the data and displays it on my site. In total there are 3 collections on the project.
  • Items (they have ids and their properties)
  • Lots / applications (and properties of the applications themselves, i.e. one of the parameters is the item id, and the second is the name of the participant)
  • Participants (to whom the applications belong, and the properties of the participants themselves)

Since we have mongo, it is clear that we are not talking about any connections. And at the design stage, the need for connections was not planned.
Use case
What we have now, in fact:
I.e. we have three collections that can be linked together, according to the principle (in the format collection: field name):
  • items:id -> applications:item
  • members:name->bids:name

The key word is “can”, but the real case is that 99% of the time I do without it. those. my site on the page displays ready-made information on specific subjects. The base "itself", following its own logic, selects subjects that are interesting to me, without building queries on my part.
But once a month (conditionally, that is, not very often). For example, I need to request statistics on a very specific subject. Since people operate with names, not id codes, let's say that I have an input field where I should enter the name of the subject and get X applications for it. The code logic here is:
items.find({name:name}).then(res.id)
     orders.find ({item:res.id}).then(res=>{
          ....
     }

  1. Those. I first ask one collection, get the required field from it, the result of which I use to search in another collection. Well, yes, it works, the indexes are set, the database is optimized, requests are not frequent, and in the interface, the entry point for users is not an input field and forms, so there are no problems. But the question is, is it right at all?
  2. Actually, in mongo you can also put down links, but as I understand it, it's not even that. that the base is not intended for this, how much is that then the data is stored as nested documents. It is obvious that if each entry in the application collection stores complete information on subjects / participants, then they will be duplicated X times, which I do not need at all. But sometimes, on the contrary, I need the result to be displayed in the format of nested documents, as if I were using JOIN from SQL. I don’t understand something in mongo and my problem is still somehow solved, or is it really necessary to switch to postgres in this case?
  3. And the third question. The fact is that I have a lot of aggregations on my project. As far as I heard, postgres will be "faster" in this case, is it so?

I don't have deadlines, i.e. it's not a problem for me to slowly move from mongo to postgres. In my case, postgres also has disadvantages. This is the lack of TTL (time-to-live) indexes. Of course, there is a similar functionality like triggers, in case of writing to the database, but this is a bit different.
In general, the question is rather that I can not worry about all this, this is (not) normal practice and continue to use mongo (well, put 1-to-1 links there) and not think about it, or still in such cases it is necessary really use something more traditional.. relational, with JOINs, etc.?
I will be glad for any answer, and I understand that using mongo comes down to a “newbie mistake” because there are a lot of tutorials now that are written under noSQL.
PS By the way, if someone wants to help with something else, or advise me on hosting, you can write here or in What config/hosting/solution would you recommend for a lightweight Mongo+Node+React (MERN/MEAN/MEVN stack) project? A :
About the size of the base, etc. I can write that I have neither Aliexpress nor HiLoad project. DB with 5-10GB, and it works fine on this config on one of the hostings: [email protected], 7GB RAM, SSD 100'000+ IOPS.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question