How can I specify a composite type for a mongoose field? The task is as follows: there are two documents "Income" and "Expense" and when they are written to the database, you must also make an entry in the table with cash flows, and in this table there will be a "doc" field in which there can be both an arrival and an expense. How to do it. Now I did it like this, doc: {id: String, ref: String}, in doc I save the document id and view, but something seems to me that this is not correct:

var mongoose = require('mongoose'); var schema = new mongoose.Schema({ kind: String, date: Date, doc: { id: String, ref: String }, purse: { type: mongoose.Schema.Types.ObjectId, ref: 'Purse' }, article: { id: String, ref: String, name: String }, sum: Number }); module.exports = mongoose.model('FlowOfFund', schema); 
  • In Mongoose, there is an enum, but with so many refs it’s worth moving to Postgres. There is also enum, with native. - Aleksei Zabrodskii
  • Thank. I will try. This is all I do for myself, so I chose mongodb to practice with it. - d.alexandr

0