Hi Guys is possible indexing populated fields
import { model, Schema } from "mongoose";
const employeeScheme = new Schema({
name: {
type: String,
required: true
},
code: {
type: String,
required: true
},
/* Company relation */
company: {
type: Schema.Types.ObjectId,
ref: "Company"
}
});
employeeScheme.index({
name: "text",
'company.name': "text"
},
export default model("Employee", countrySchema);
const e = await Employee.find({ $text: { $search: "My Company name" } })
.sort({ createdAt: -1 })
.limit(1)
.populate({
path: "company",
populate: {
path: "logo"
}
});
not searching the company name field
Any Idea???
No responses yet.