Extended search is not working (Foreach of Undefined error)

When I am trying to do extended search in ‘User’ collection, it shows this error.

[forest] :deciduous_tree::deciduous_tree::deciduous_tree: Unexpected error: Cannot read property ‘forEach’ of undefined
“stack”: “TypeError: Cannot read property ‘forEach’ of undefined\n at E:\Incard\development\incard-api\node_modules\forest-express-mongoose\dist\services\search-builder.js:80:40\n at E:\Incard\development\incard-api\node_modules\lodash\lodash.js:4967:15\n at baseForOwn (E:\Incard\development\incard-api\node_modules\lodash\lodash.js:3032:24)\n at E:\Incard\development\incard-api\node_modules\lodash\lodash.js:4936:18\n at Function.forEach (E:\Incard\development\incard-api\node_modules\lodash\lodash.js:9410:14)\n at _callee2$ (E:\Incard\development\incard-api\node_modules\forest-express-mongoose\dist\services\search-builder.js:42:15)\n at tryCatch (E:\Incard\development\incard-api\node_modules\regenerator-runtime\runtime.js:63:40)\n at Generator.invoke [as _invoke] (E:\Incard\development\incard-api\node_modules\regenerator-runtime\runtime.js:294:22)\n at Generator.next (E:\Incard\development\incard-api\node_modules\regenerator-runtime\runtime.js:119:21)\n at asyncGeneratorStep (E:\Incard\development\incard-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24)\n at _next (E:\Incard\development\incard-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9)\n at E:\Incard\development\incard-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:32:7\n at new Promise ()\n at SearchBuilder.getConditions (E:\Incard\development\incard-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:21:12)\n at _callee3$ (E:\Incard\development\incard-api\node_modules\forest-express-mongoose\dist\services\search-builder.js:162:28)\n at tryCatch (E:\Incard\development\incard-api\node_modules\regenerator-runtime\runtime.js:63:40)\n at Generator.invoke [as _invoke] (E:\Incard\development\incard-api\node_modules\regenerator-runtime\runtime.js:294:22)\n at Generator.next (E:\Incard\development\incard-api\node_modules\regenerator-runtime\runtime.js:119:21)\n at asyncGeneratorStep (E:\Incard\development\incard-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24)\n at _next (E:\Incard\development\incard-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9)\n at E:\Incard\development\incard-api\node_modules\@babel\runtime\de_modules\regenerator-runtime\runtime.js:294:22)\n at Generator.next (E:\Incard\development\incard-api\node_modules\regenerator-runtime\runtime.js:119:21)”

The User collection has relationship with other smart collections.
So the smart collections are related data of User collection.
I wonder if this can cause the error.

Hello @Meylis_Amanov,

Thank you for this feedback.

In order to find where does this problem comes from, can you please temporarily drop the smart collections that “User” collection relates to, and try again an extended search?


Good morning Sliman.
Yes, I tried it.
I removed all smart fields, smart actions, and relationships defined in ‘/forest/User.js’ file for testing.
But the same error still remains.
Can you explain me how Extended Search function was implemented?
Seems like that it uses forEach somewhere inside the function.
FYI, extended search is working for other collections.
But it doesn’t work for User, Archive and Onboarding collection.
I did a tricky thing with those collections.
They all use one MongoDB schema.
This is part of my /models/user.js file.

const User = db.model(‘User’, userSchema, ‘users’);
const Onboarding = db.model(‘Onboarding’, userSchema, ‘users’);
const Archive = db.model(‘Archive’, userSchema, ‘users’);

So in my MongoDB, there is only one collection named ‘users’.
But I created those three collections in ForestAdmin to split users with their status(users.status===‘active’ then it goes to User->Active segment in FA,
users.status===‘suspended’ then it goes to User->Suspended segment in FA,
user.status === ‘sign_up’ then it goes to Onboarding->SignUp segment in FA,
user.status === ‘closed’ then it goes to Archive->Closed segment.
user.status === ‘rejected’ then it goes to Archive->Rejected segment.)

Steve in your tech team helped me to create three ForestAdmin collections from one DB collection.
He has a brief understanding on our project structure.
I think, creating three collections from one DB collection causes the issue with Extended search.
I wonder if there’s a way to solve it. Thank you :slight_smile:

Hello @Meylis_Amanov,

The workaround to define 3 Forest collections based on one Mongo collection looks fine.
It looks not related to the extended search problem.
To be sure there is no collision when passing the same schema multiple times, can you deactivate Onboarding and Archive and test User extended search?


I devativated Onboarding and Archive collection.
But the error still remains :frowning:

Ok, so that means the extended search is failing on a simple mongo collection, without any relationship defined.
I will tell the team.


screenshot sent in private

Hello @Meylis_Amanov,

I just tried on a very basic collection and it worked.

Can you tell me what’s your forest-express-mongoose version?

Hi @adriguy
In my package.json file. It says.

"forest-express-mongoose": "^8.4.5",


I just tried again on basic collection with relationships, it works well (on forest-express-mongoose 8.5.0).
Would you mind sharing the version given in your package-lock.json?

Is the User collection itself a simple or a smart collection?
Would you mind sharing your forest/user.js file?

And if I understand well, you are using smart segment as well in your collections?
Are you testing the extend search on a segment or on the main list?


In FA User, Archive, Onboarding collections are from one MongoDB collection.
And we can only click segments inside the collections.
So, yes, I am doing extended search in segment level.
And in package-lock.json it says
“forest-express-mongoose”: {
“version”: “8.4.6”,

And I am not using smart segment.

Would you mind sharing your forest/user.js file please?

It’s too big to write here.
I messaged it to you.


So in order to understand where the issue is from, did you try to:

  • Do the extend search on the main list (not on segment level)?
  • Comment out all the smart fields? Along with smart actions?

I tried both of them.
But it doesn’t work :frowning:

Hey @Meylis_Amanov :wave:

I’m able to reproduce the issue. It seems related to the selectedCustomerTypes. You can eventually test to comment out the selectedCustomerTypes property in your model to check if I’m right :slight_smile:

I’ll open a bug report on our end. Be sure you’ll be pinged once fixed :+1:

Sorry for the inconvenience

1 Like

Hi @jeffladiray .
I commented selectedCustomerTypes and now Extended Search works on my side.
Thank you for finding the bug.
Btw, we need to use the field, so I can’t comment it out.
So I’ll be appreciate if you fix the bug and ping me soon.
Thanks :slight_smile:

1 Like

I commented selectedCustomerTypes and now Extended Search works on my side.
Thank you for finding the bug.

Yes of course, I just wanted to make sure I was able to reproduce the same issue as yours.
The ticket has been dispatch so indeed, you’ll be pinged once fixed.

Have a nice day!


Hi @jeffladiray, I hope you are doing well.
I guess that is not big issue, but it blocks us for a long time.
Can you please fixt it and ping me?
Thank you.