Мне нужно установить поле из другой коллекции в качестве внешнего ключа для моей схемы mongoose.
У меня есть счетчик pid
до productSchema
. Мне нужно установить pid
в качестве иностранного ключа на orderSchema
const orderSchema = mongoose.Schema({
id: mongoose.Schema.Types.ObjectId,
product: { type: mongoose.Schema.Types.ObjectId, ref: 'Product',
required:
true },
quantity: { type: Number, default: 1 }
});
const productSchema = mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
name: { type: String, required: true },
price: { type: Number, required: true },
productImage: { type: String }
});