This requires detailed analysis of specific businesses.
If the brand name is set to ObjectId 的话,就说明有另外一个 collection, the brand is stored. This is a typical relational database method. For mongodb, each time you want to obtain the brand name of a product, you need one more read operation.
If set to String, all product information and brand name can be retrieved in one operation, but it is very troublesome to modify the brand. If you also need to obtain some information about the brand in one request, such as the country where the brand is located, you still have to do it again. When doing a query, the scalability is not good enough.
This can solve the scalability problem, and the query speed is also very fast. If the product brand information is not updated very often, then I recommend this. Although the degree of data redundancy is increased, the query speed is improved. This is an anti-paradigm.
If the brand information is updated frequently, it is still good to use ObjectId. Although it requires one more query, it improves reliability.
This requires detailed analysis of specific businesses.
If the brand name is set to
ObjectId
的话,就说明有另外一个collection
, the brand is stored. This is a typical relational database method. For mongodb, each time you want to obtain the brand name of a product, you need one more read operation.If set to
String
, all product information and brand name can be retrieved in one operation, but it is very troublesome to modify the brand. If you also need to obtain some information about the brand in one request, such as the country where the brand is located, you still have to do it again. When doing a query, the scalability is not good enough.If set to
Object
For example:This can solve the scalability problem, and the query speed is also very fast. If the product brand information is not updated very often, then I recommend this. Although the degree of data redundancy is increased, the query speed is improved. This is an anti-paradigm.
If the brand information is updated frequently, it is still good to use
ObjectId
. Although it requires one more query, it improves reliability.