D
D
Dmitrii Solovev2016-06-06 15:23:24
MongoDB
Dmitrii Solovev, 2016-06-06 15:23:24

How to implement schemas with subtypes in mongoose?

Those. scheme, documents which can have different types, and different or identical fields depending on the type.
For example, I have a transaction schema that has common fields: amount, date, and type.
The type can be income, expense or transfer. And depending on the type, the document may have different fields that are unique to only one type.
Income and expenditure: account name, categories ...
Translation: account name from where, account name to ...
PS. I tried to use the Discriminator keys, which creates three subtypes, each has its own scheme, but it didn’t work, because there were problems with queries and the inability to change the scheme when updating (you can’t just take and change the document from one type to another, you need to delete it, then create again but from a different schema)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Ptolemy_master, 2017-08-26
@Ptolemy_master

How about a generic schema "inserted" into an object as a reference? That is, different schemes refer to a common one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question