search

Home  >  Q&A  >  body text

node - mongodb database design mongoose schema

Order table design in trading scenario:

Assume there are four products. The order data of each product must have the same parts, such as: order number, order owner, order type, order status, order tracking timeline. At the same time, orders for different products also have their own special The data.

Do you define different schemas for different product designs, or do you only define the schema for one order, but specify a special
subdocument to store data unique to different products?

Should orders be stored in different collections according to different product types, or directly stored in the same order table?

扔个三星炸死你扔个三星炸死你2745 days ago1066

reply all(3)I'll reply

  • phpcn_u1582

    phpcn_u15822017-06-16 09:21:06

    You can put orders in the same collection and distinguish them by product type.
    There is no need to put them in different collections according to different types. Mongodb is also generated for this kind of non-strict field alignment data.

    reply
    0
  • 迷茫

    迷茫2017-06-16 09:21:06

    I think it must be put under one set, after all, there are only a few different parts

    reply
    0
  • 女神的闺蜜爱上我

    女神的闺蜜爱上我2017-06-16 09:21:06

    It is recommended to consider taking advantage of MongoDB's dynamic schema, which means that each document does not need to follow the same schema.

    The official document has detailed instructions on data modeling for your similar needs, please refer to the document link below:

    https://docs.mongodb.com/ecos...

    For reference.

    Love MongoDB! Have fun!

    reply
    0
  • Cancelreply