Answer the question
In order to leave comments, you need to log in
How to implement link function in mongodb?
Given. Product creation page and category creation page.
They have a circuit trace
const {Schema, model, Types} = require('mongoose')
const schema = new Schema({
name: {type: String, required: true},
price: {type: Number, required: true},
rating: {type: Number, default: 4.7},
weight: {type: String, required: true},
image: { type: String, trim: true},
category: {type: Types.ObjectId, ref: "MyCategory"}
})
module.exports = model("MyProduct", schema)
const {Schema, model, Types} = require('mongoose')
const schema = new Schema({
name: {type: String, required: true, unique: true},
image: {type: String, required: true},
owner: [{
type: Types.ObjectId,
ref: "MyProduct"
}]
})
module.exports = model("MyCategory", schema)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question