mongoose-fuzzy-searching
mongoose-fuzzy-searching copied to clipboard
Search in Referenced Object Id Field
Do you want to request a feature, an issue, or report a bug? feature
What is the current behaviour? Does not look into referenced object title or name.
If the current behaviour is a bug, please provide the steps to reproduce.
What is the expected behaviour? Need to search in referenced object e,g; A product has field category (object Id) and if a user search for for example 'laptop' it should search for laptop in product name, keywords and title of category too, but the category filed id object id refernce.
If this is a feature request, what is the motivation or use case for changing the behaviour?
Please mention other relevant information such as Node.js and mongoose version.
I want that feature too, but I think the mongoose find method does not support this either. I solve this by creating a _category_name field on the product and then in the validate middleware I set the value. Something like this:
// eslint-disable-next-line func-names
schema.pre("validate", async function () {
const helper = await HelperModel.findById(this.helper).exec();
// eslint-disable-next-line no-underscore-dangle
this._helper_name = helper.name;
// eslint-disable-next-line no-underscore-dangle
this._helper_username = helper.username;
});
I also do this to translate enum values to local strings, so the user can search in enums too.
@juliushuck Yes i have did the similar thing by saving category name into keywords array.