Regarding the modeling of mongodb, some people suggest that I change the “brand name” of “goods” from ObjectId to string. Is that okay?

  mongodb, question

He said it was more convenient to inquire. Yes, fools also know it is convenient to inquire. I questioned whether it would be bad to store it like this, but he said there was a shortId or something, so ask for an answer!

This requires specific business analysis.
If the brand name is set toObjectIdIf so, it means there is another one.collectionStore the brand. This is a typical way of relational database. For mongodb, every time you want to obtain the brand name of a commodity, you have to read it once more.

If set toString, one operation can take out all the commodity information and brand name, but it is very troublesome to modify the brand. If you need to obtain some brand information in one request, such as the country where the brand is located, then you still need to do another query, and the scalability is not good enough.

If set toObjectFor example:

javascript{
 item:"",
 price:100,
 brand:{
 name: "micorsoft",
 country: "US"
 }
 }

This can solve the problem of scalability, and the query speed is also very fast. If the brand information of the product is not updated very much, then I suggest doing so. Although the degree of data redundancy is increased, the query speed is increased, which is the inverse normal form.

If the brand information is updated frequently, useObjectIdIt is still good. Although there is one more query, the reliability has been improved.