I have a mongoose find request, and I have a first mongoose schema who contains this (the client) :
client: { type: ObjectId, ref: 'Client' },
And I have the client schema :
new mongoose.Schema({
firstName: String,
lastName: String,
company: String,
companyAsPrimaryName: Boolean,
})
I want to do a find request in the first schema depends on the client property companyAsPrimaryName boolean. If it's false : I want to sort on firstName + lastName, and if it's true, I want to sort on company.
I have no idea how to do this, I already checked an answer and I found nothing.
Thanks for your help