Will this be considered incorrect when working with NoSQL databases? Should I not think about “relationships” when working with NoSQL?
There are so many questions about the investment case, and it comes down to very little.
Signs that were not mentioned here that need to be considered if you want to insert:
- Will the size of the document increase in bulk? If so, the document can often move around the disk, this is bad.
- Will the linked string contain many references to the collection I'm working on (i.e.
video
cannot insert user
). If so, you may have problems copying redundant data from the corresponding line to the subdocument, especially when updating redundant data. - How do I display these results?
Displaying results is always a key decider in whether to embed. If you need to split pages into a large number of lines, say 1000, you will need to use the $slice
operator in a regular query or in an aggregation structure. At 1000, I admit that it can be pretty fast, but sooner or later this memory operation will be slower than a regular procedure (it should always be infact).
If you need complex sorting and display of subdocuments, you may want to separate them and create a document structure instead:
{ "string": "foobar", "owners": [ ObjectId(), ObjectId(), ObjectId() ] }
I think it could be a more realistic structure for your data anyway, since owner
sounds like a user
string in the users
collection.
Instead of filling out subdocuments, possibly changing user data, you can simply reference their _id
. This is pretty kool, because you can embed relationships, but at the same time, the document will grow very little, which, I hope, means that there is a small chance that the disk will constantly move, not only this, but a smaller working set, which will create more efficient overall work. Not only this, but, of course, the owner’s _id
rarely changes, so the only operations that you need to most likely throw at this subset of data are creating and deleting.
Return to complex sorting and pagination. With this data, you can, of course, get all the owner
tags with one round trip, and then another round trip, you can query these owners for rows in the users
table with a regular query using $in
, which allows you to have a complex display .
So, this structure as a whole, I found, is very effective.
Of course, this structure depends on your request, it would be better to place the row identifier for the user instead, but in this case it is not, since the user can presumably own many lines, I would say that it is a lot → many links built-in to a string.
Hope this helps, and I didn’t go round,