简体   繁体   中英

How to implement polymorphism in MongoDB?

There seems to be concepts of implementing polymorphism with MongoDB but I can't find any good documentation on how to do it.

Can I do this as part of MongoDB itself - or do I have to model it in Mongoose ( I use Nodejs )

To give an example of the type of data I want to store/ retrieve, I want to store 2 types of products in a product collection. Simple and Grouped.

Both types will have

  • _id
  • sku
  • name

Grouped products will have

  • associated_ids an array of id's to link to simple products
  • meta_name
  • meta_description

Simple Products will have

  • buy_price
  • sell_price

Is there a good data modelling program for MongoDB as well?

If someone can point me in the right direction, I don't think I am looking in the right place.

Thanks Martin

Example of usage MongoDb Polymorphism here .

You may find out course "Data Modeling" of MongoDb University helpful. There are lectures "Schema Versioning Pattern" and "Polymorphic Pattern" gives some steps of modeling polymorphism in MongoDb.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM