D
D
d1zz72021-09-11 11:47:01
MongoDB
d1zz7, 2021-09-11 11:47:01

How to make default values ​​from another document?

For example:

const schema = new Schema({
        order: { type: Schema.Types.ObjectId, ref: 'orders', required: true },
        user: { type: Schema.Types.ObjectId, ref: 'user', required: true },
        offeredPrice: { type: Schema.Types.Decimal128,  default: 0.00 }
    },
    { timestamps: true }
);

How can offeredPrice default to the value of price in the order collection to which it is bound. :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question