I would like to retrieve with a search field the channels according to the user’s first name.
const UserSchema = new mongoose.Schema({
email: {
type: String,
require: true,
trim: true,
unique: true
},
password: {
type: String,
require: true,
trim: true,
unique: true
},
_profile: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Profile',
require: true,
unique: true
}
})
const ProfileSchema = new mongoose.Schema({
name: {
type: String,
require: true,
trim: true,
unique: true
},
firstname: {
type: String,
require: true,
trim: true,
unique: true
}
})
const ChannelSchema = new mongoose.Schema({
title: {
type: String,
require: true,
trim: true,
unique: true
},
_user: {
type: String,
require: true,
trim: true,
unique: true
}
})
const User = mongoose.model('User', UserSchema)
const Profile = mongoose.model('Profile', ProfileSchema)
const Channel = mongoose.model('Channel', ChannelSchema)
I used to populate
function to retrieve the data from the joins
let ChannelSearch = await Channel
.find()
.populate({
path: '_user',
select:'-password',
populate: {
path: '_profile'
}
})
but where I block is how to retrieve the channels based on the user’s first name
I can’t seem to find how it is possible to make a like
request through the populate
function
Thank you in advance for your help !! =)