alex42
December 7, 2022, 2:48pm
1
Feature(s) impacted
Search
Observed behavior
Search don’t work on nested fields…
Expected behavior
How to enable search on nested fields?
Context
Hello,
I’m using forest admin with mongodb, and I’m wondering how to enable or how to add code to provide a search on nested fields? See example:
I’ve 2 collections
Users (each user is linked to a family with an ID)
Family
ID
Name
How to provide search from Users collection with the family name? from this input: (without advanced filters)
Thanks for your help,
Alexandre
That depends on which agent you are using.
With @forestadmin/agent
(released last july), search can be customized by passing a custom handler to the replaceSearch
method.
Here is the documentation: https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/search
With forest-express
, the API is much lower level, and customers were expected to override the list route, and implement their own behavior there.
Here is the documentation: https://docs.forestadmin.com/documentation/reference-guide/routes
alex42
December 7, 2022, 4:48pm
3
Hello Romain!
Thanks for your quick response, I’m using forest-express-mongoose, so I need to use https://docs.forestadmin.com/documentation/reference-guide/routes right?
And did you have any example of implementation ?
Thanks,
Alex
alex42
December 28, 2022, 1:49pm
4
Hello,
Any help on this topic? It’s really ruining our experience with Forest…
Thanks,
Alex
Hey @alex42 , and sorry for the super delayed response.
I’m using forest-express-mongoose
Are you using the fields flattener
feature to deal with your nested fields ?
(https://docs.forestadmin.com/documentation/how-tos/setup/flatten-nested-fields-mongodb )
alex42
January 5, 2023, 1:40pm
7
Hello @jeffladiray ,
Thanks for your reply, my issue is more with populated (from other collections) fields (who are not searchable) and not about flattened fields (I guess)
To re-explain my problem, the “Account number” field is populated from another collection, but when I search “Himalia” in the search I got 0 results…
Thanks a lot for your help
Did you try with the extended search
feature?
By default, search only works on the default fields available for your specific model, and extended search
allow you to search inside belongsTo
relations.
If it doesn’t work, a smart field referencing the field you want to search on + an implementation of the associated search could do the trick here.