🔥یلدا با راکت با (( ۷۰ درصد )) تخفیف! یلدا طولانی است، اما این تخفیف نه.
مشاهده دورههاسلام
وقتی که برای ارتباط بین Collection ها از Virtual استفاده میشه چطوری باید id رو توی virtual ذخیره کرد؟؟؟؟
const UserSchema = new Schema({
name: {
first: String,
family: String
},
username: String,
admin: {type: Boolean, default: false},
email: {type: String, required: true, unique: true},
password: {type: String, required: true},
age: Number,
}, {timestamps: true, toJSON: {virtuals: true}});
UserSchema.virtual('products', {
ref: 'Product',
localField: '_id',
foreignField: 'user_id',
});
const ProductSchema = new Schema({
user_id: {type: Schema.Types.ObjectId, ref: 'User'},
cat_id: {type: Schema.Types.ObjectId, ref: 'Category'},
title: {type: String, required: true, unique:true},
body: {type: String, required: true},
price: {type: Number, required: true},
imageUrl: {type: String, required: true},
}, {timestamps: true, toJSON: {virtuals: true}});
منظورم ذخیره شدن id محصولات در products هستش
ممنون میشم راهنمایی کنید من رو
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟