My code simply is I want to let the user bookmark different types of products. This is on the user schema
const UserSchema = new mongoose.Schema({
// ...
bookmarks: [
{
product_type: { // this should be the refPath
type: String,
enum: ['vehicle', 'nutrition', 'accessory', 'etc...'],
},
product_id: {
type: mongoose.Types.ObjectId,
refPath: '' // Vehicle, Nutrition, etc..
},
},
]
});
How can I set the refPath to look on the property that is in the same object. or should I follow a different structure?
And how can I correctly populate the result.
Update 1:
I temporarily solved the problem by dividing the bookmarks as follows
bookmarks: {
vehicle: [ mongoose.Schema.Types.ObjectId ],
accessory: [ mongoose.Schema.Types.ObjectId ],
...
}
However this is not a very scalable solution