# Search doesn't return anything

**URL:** <https://community.forestadmin.com/t/search-doesnt-return-anything/6573>\
**Category:** Help me!\
**Created:** [August 18, 2023, 10:02am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573 "2023-08-18T10:02:27Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 18, 2023, 10:02am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/1 "2023-08-18T10:02:27Z")

</div>

## Feature(s) impacted

Search in sub-collection, when trying to add an existing student to lead students.

## Observed behavior

Search is continously loading when looking for an item, through button “Add existing …”.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/7/72244597c2afec605891df4bd814ccf0f60d72e5.png)

If I look for a missing term, I’ve got the right info :

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/f/f8c738c10f913160559f443bf3bfa5ae60773e02.png)

So, it seems it simply doesn’t return the results.

## Failure Logs

No failure log.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/3/3ab5d9f27769a42cb10191bf33571a5ca63d8db9.png)

## Context

- Project name: `lereacteur-admin`
- Team name: Operations
- Environment name: dev/prod
- Agent (forest package) name & version: `"forest-express-mongoose": "^8.7.9"`
- Database type: MongoDB

---

<div class="post-metadata">

**Author:** ![shohanr](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/shohanr/32/4999_2.png) [@shohanr](https://community.forestadmin.com/u/shohanr)\
**Post date:** [August 18, 2023, 2:43pm UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/2 "2023-08-18T14:43:33Z")

</div>

Hi @XavierColombel ,

1. Did the search was working previously ? (if yes, what change did you make recently and when did it start to happen?)
2. Is it working on other collections?
3. Do you still have records before searching ?

Best regards,

Shohan

---

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 18, 2023, 3:44pm UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/4 "2023-08-18T15:44:55Z")

</div>

**Did the search was working previously ? (if yes, what change did you make recently and when did it start to happen?)**  
Yes and I’ve recently moved to from version 7 to 8.  
**Is it working on other collections?**  
Yes but not with students sub-collection.  
**Do you still have records before searching ?**  
Yes

---

<div class="post-metadata">

**Author:** ![shohanr](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/shohanr/32/4999_2.png) [@shohanr](https://community.forestadmin.com/u/shohanr)\
**Post date:** [August 21, 2023, 12:28pm UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/5 "2023-08-21T12:28:19Z")

</div>

Hi @XavierColombel,

We have some breaking changes from V7 to V8, could you check with [this documentation](https://docs.forestadmin.com/documentation/extra-help/maintain/upgrade-notes-sql-mongodb/upgrade-to-v8) if your setup is up-to-date please ?  
Could you please send me how did you declare your sub-collection?

Best regards,

Shohan

---

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 21, 2023, 2:31pm UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/6 "2023-08-21T14:31:53Z")

</div>

My setup is up-to-dating, following the documentation. Everything is working but this.

My subcollection `students` is declared like this in the `lead` model :

```js
students: [{ type: Mongoose.Schema.Types.ObjectId, ref: "Students" }],

```

I’ve to tell I have other subcollections, declared the same way and it’s working fine.

The main problem is it’s loading permanently, when I look for a student… And I’ve no error log. Can yo please investigate by your side please and give me errors you might have? It’s a big problem for us and we pay Forest.

Thanks.

---

<div class="post-metadata">

**Author:** ![shohanr](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/shohanr/32/4999_2.png) [@shohanr](https://community.forestadmin.com/u/shohanr)\
**Post date:** [August 22, 2023, 9:19am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/7 "2023-08-22T09:19:12Z")

</div>

Hi @XavierColombel,

1. In your search, when it continuously loading, what does the network returns ?
2. The display field of your Students collection is a Smart Field called “Nom complet”. Could I have the definition of this field ?
3. In the search query, is the “Nom complet” is in the payload of the response ?

Best regards,

Shohan

---

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 22, 2023, 9:33am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/8 "2023-08-22T09:33:33Z")

</div>

**1. In your search, when it continuously loading, what does the network returns ?**  
When I type something it returns an error from ember, I guess :  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/c/c38c7b9e8a8f46d5a8d4af8174f19499f4a3010a.png)

**2. The display field of your Students collection is a Smart Field called “Nom complet”. Could I have the definition of this field ?**  
It’s the concatenation of first name, last name and email, like this : `John DOE (johndoe@email.com)` for instance.

**3. In the search query, is the “Nom complet” is in the payload of the response ?**  
`Nom complet` is the reference field and the payload, yes.

![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/8/8bf2d1da11f8db0107f8d851d921171cf52b5212.png)

---

<div class="post-metadata">

**Author:** ![nbouliol](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nbouliol/32/5777_2.png) [@nbouliol](https://community.forestadmin.com/u/nbouliol)\
**Post date:** [August 24, 2023, 10:10am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/9 "2023-08-24T10:10:48Z")

</div>

Hello @XavierColombel

We are still trying to identify and reproduce your issue.

Can you please share with us the http response you receive from your agent when searching for a student to add ?

Nicolas

---

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 24, 2023, 10:31am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/10 "2023-08-24T10:31:56Z")

</div>

If I search “valerie”, I’ve got this :

```js
{
    "meta": {
        "decorators": {
            "0": {
                "id": "xxxxxx",
                "search": [
                    "firstname",
                    "Nom complet"
                ]
            }
        }
    },
    "data": [
        {
            "type": "Students",
            "id": "xxxxxx",
            "attributes": {
                "Nom complet": "Valerie XXXX XXX (xxxxx@yahoo.fr)",
                "email": "xxxxx@yahoo.fr",
                "telephone": "+xxxxxxxx",
                "firstname": "Valerie",
                "lastname": "XXXX XXX",
                "birthDate": "1987-06-05T00:00:00.000Z",
                "zipCode": "xxxxx",
                "slackId": "XXXXXX",
                "slackAvatar": "https://avatars.slack-edge.com/xxx_1024.jpg",
                "mailinglist": true,
                "relationships": {
                    "githubMember": {
                        "data": [
                            {
                                "type": "GithubMembers",
                                "id": "xxxxx"
                            }
                        ],
                        "links": {
                            "related": {
                                "href": "/forest/Students/xxxxx/relationships/githubMember"
                            }
                        }
                    },
                    "sessions": {
                        "links": {
                            "related": {
                                "href": "/forest/Students/xxxxx/relationships/sessions"
                            }
                        }
                    },
                    "leads": {
                        "links": {
                            "related": {
                                "href": "/forest/Students/xxxxx/relationships/leads"
                            }
                        }
                    },
                    "commentsArr": {
                        "links": {
                            "related": {
                                "href": "/forest/Students/xxxxx/relationships/commentsArr"
                            }
                        }
                    },
                    "documents": {
                        "links": {
                            "related": {
                                "href": "/forest/Students/xxxxx/relationships/documents"
                            }
                        }
                    },
                    "exams": {
                        "links": {
                            "related": {
                                "href": "/forest/Students/xxxxx/relationships/exams"
                            }
                        }
                    }
                }
            }
        ],
        "included": [
            {
                "type": "GithubMembers",
                "id": "xxxxx",
                "attributes": {
                    "_id": "xxxxx"
                }
            }
        ]
    }

```

So, for me it’s a good response, but nothing appears and the loader is still turning.

PS : I’ve cleaned the json.

---

<div class="post-metadata">

**Author:** ![nbouliol](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nbouliol/32/5777_2.png) [@nbouliol](https://community.forestadmin.com/u/nbouliol)\
**Post date:** [August 24, 2023, 12:49pm UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/11 "2023-08-24T12:49:56Z")

</div>

Thank you for your response.

Can you please try to update the smart field name so it does not contain spaces ?

```javascript
fields: [{
    field: 'NomComplet",
    ...

```

You can update the display name of the field in the Students collection settings to match _“Nom complet”_.

---

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 24, 2023, 1:40pm UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/12 "2023-08-24T13:40:38Z")

</div>

> [@nbouliol](#):
>
> `NomComplet`

Yes, same problem, same loader turning indefinitely.

---

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 24, 2023, 7:44pm UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/13 "2023-08-24T19:44:31Z")

</div>

I found that with certain search I’ve no problem.

For instance, looking for `foui`, I’ve got this response (and it’s working) :

```json
{
  "meta": {
    "decorators": {
      "0": {
        "id": "5e99fa2ec9aaef788cc6c335",
        "search": ["email", "lastname", "Nom complet"]
      }
    }
  },
  "data": [
    {
      "type": "Students",
      "id": "5e99fa2ec9aaef788cc6c335",
      "attributes": {
        "Nom complet": "xxxxx Fouite (fouite.xxxxx@gmail.com)",
        "email": "fouite.xxxxx@gmail.com",
        "firstname": "xxxxx",
        "lastname": "Fouix",
        "birthDate": "1980-09-04T22:16:40.000Z",
        "country": "France",
        "slackAvatar": "https://avatars.slack-edge.com/xxxxx_1024.jpg",
        "isFlagged": false,
        "createdAt": "2020-04-17T18:48:23.314Z",
        "updatedAt": "2020-04-17T18:48:23.314Z",
        "_id": "5e99fa2ec9aaef788cc6c335"
      },
      "relationships": {
        "sessions": {
          "links": {
            "related": {
              "href": "/forest/Students/5e99fa2ec9aaef788cc6c335/relationships/sessions"
            }
          }
        },
        "leads": {
          "links": {
            "related": {
              "href": "/forest/Students/5e99fa2ec9aaef788cc6c335/relationships/leads"
            }
          }
        },
        "commentsArr": {
          "links": {
            "related": {
              "href": "/forest/Students/5e99fa2ec9aaef788cc6c335/relationships/commentsArr"
            }
          }
        },
        "documents": {
          "links": {
            "related": {
              "href": "/forest/Students/5e99fa2ec9aaef788cc6c335/relationships/documents"
            }
          }
        }
      }
    }
  ]
}

```

And if I look for `valeri` (it’s not working) :

```json
{
  "meta": {
    "decorators": {
      "0": {
        "id": "641083c3f447ae00141a63ac",
        "search": ["firstname", "Nom complet"]
      }
    }
  },
  "data": [
    {
      "type": "Students",
      "id": "641083c3f447ae00141a63ac",
      "attributes": {
        "Nom complet": "Valerie XXXX XXX (xxxxxx@yahoo.fr)",
        "email": "xxxxxx@yahoo.fr",
        "telephone": "+xxxxxx",
        "firstname": "Valerie",
        "lastname": "XXXX XXX",
        "birthDate": "1987-06-05T00:00:00.000Z",
        "zipCode": "69570",
        "slackAvatar": "https://avatars.slack-edge.com/xxxxx_1024.jpg",
        "createdAt": "2023-03-14T14:25:07.187Z",
        "updatedAt": "2023-03-14T14:25:07.187Z",
        "_id": "641083c3f447ae00141a63ac"
      },
      "relationships": {
        "githubMember": {
          "data": [
            { "type": "GithubMembers", "id": "641effa7f79a140014a47a3b" }
          ],
          "links": {
            "related": {
              "href": "/forest/Students/641083c3f447ae00141a63ac/relationships/githubMember"
            }
          }
        },
        "sessions": {
          "links": {
            "related": {
              "href": "/forest/Students/641083c3f447ae00141a63ac/relationships/sessions"
            }
          }
        },
        "leads": {
          "links": {
            "related": {
              "href": "/forest/Students/641083c3f447ae00141a63ac/relationships/leads"
            }
          }
        },
        "commentsArr": {
          "links": {
            "related": {
              "href": "/forest/Students/641083c3f447ae00141a63ac/relationships/commentsArr"
            }
          }
        },
        "documents": {
          "links": {
            "related": {
              "href": "/forest/Students/641083c3f447ae00141a63ac/relationships/documents"
            }
          }
        },
        "exams": {
          "links": {
            "related": {
              "href": "/forest/Students/641083c3f447ae00141a63ac/relationships/exams"
            }
          }
        }
      }
    }
  ],
  "included": [
    {
      "type": "GithubMembers",
      "id": "641effa7f79a140014a47a3b",
      "attributes": { "_id": "641effa7f79a140014a47a3b" }
    }
  ]
}

```

Do you see any problem ?

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [August 29, 2023, 6:36am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/14 "2023-08-29T06:36:17Z")

</div>

There is something a bit weird is that you don’t have the same fields for both entities 🤔. Did you customized the serializer of forestadmin ?  
What could be the problem is your `GithubMembers` relationships, I will investigate a bit more 🕵️‍♂️

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [August 29, 2023, 6:40am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/15 "2023-08-29T06:40:22Z")

</div>

Okey I think it is the issue. Your `GithubMember` relationships is return as a `HasMany` but it’s actually a `BelongsTo` 🤔

```javascript
          "data": [
            { "type": "GithubMembers", "id": "641effa7f79a140014a47a3b" }
          ],
          "links": {
            "related": {
              "href": "/forest/Students/641083c3f447ae00141a63ac/relationships/githubMember"
            }
          }
        },

```

It should be:

```javascript
        "githubMember": {
          "data": { "type": "GithubMembers", "id": "641effa7f79a140014a47a3b" },
          "links": {
            "related": {
              "href": "/forest/Students/641083c3f447ae00141a63ac/relationships/githubMember"
            }
          }
        },

```

---

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 29, 2023, 8:27am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/16 "2023-08-29T08:27:18Z")

</div>

@anon62739609 here is my setup (and I didn’t change or customize anything) in `student` model :

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/1/191ace5fb06e712feaac107bc30359a2750cd8d6.png)

Could you tell me how to solve this please ?

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [August 29, 2023, 10:09am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/17 "2023-08-29T10:09:42Z")

</div>

The issue is coming from your agent (your backend). Could your show me the declaration of your Student model ? And the data in database of your **valeri** student

---

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 29, 2023, 11:49am UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/18 "2023-08-29T11:49:53Z")

</div>

@vince Actually, I didn’t update anything since more than a year, and it always worked.

Here is the model (simplified) :

```js
module.exports = (mongoose, Mongoose) => {
  const schema = Mongoose.Schema(
    {
      email: String,
      telephone: String,
      firstname: String,
      lastname: String,
      githubMember: {
        type: Mongoose.Schema.Types.ObjectId,
        ref: "GithubMembers",
      },
      sessions: [
        { type: Mongoose.Schema.Types.ObjectId, ref: "SessionsApollo" },
      ],
      leads: [{ type: Mongoose.Schema.Types.ObjectId, ref: "Leads" }], // !!!!!!
      infos: String,
      commentsArr: [
        { type: Mongoose.Schema.Types.ObjectId, ref: "CommentsStudents" },
      ],
      mailinglist: Boolean,
      documents: [{ type: Mongoose.Schema.Types.ObjectId, ref: "Documents" }],
      status: {
        type: String,
        default: "prework",
      },
      isFlagged: {
        type: Boolean,
        default: false,
      },
      linkedIn: String,
      exams: [
        {
          type: Mongoose.Schema.Types.ObjectId,
          ref: "SessionsApollo",
        },
      ],
      createdAt: {
        type: Date,
        default: Date.now,
      },
      updatedAt: {
        type: Date,
        default: Date.now,
      },
    },
    {
      timestamps: false,
    }
  );
  return mongoose.model("Students", schema, "students");
};

```

And object for “valeri” :

```json
{
  "_id": {
    "$oid": "641083c3f447ae00141a63ac"
  },
  "sessions": [
    {
      "$oid": "62b2f80705ed090018f35200"
    }
  ],
  "leads": [
    {
      "$oid": "63d79e7e1ab49c0016ec3418"
    },
    {
      "$oid": "64de2128c201380014f68360"
    }
  ],
  "commentsArr": [],
  "documents": [
    {
      "$oid": "641083ecf447ae00141a63b0"
    }
  ],
  "status": "training",
  "isFlagged": false,
  "exams": [],
  "email": "xxxxx@yahoo.fr",
  "telephone": "+33xxxxxxxxx",
  "firstname": "Valerie",
  "lastname": "XXXX",
  "mailinglist": true,
  "createdAt": {
    "$date": "2023-03-14T14:25:07.187Z"
  },
  "updatedAt": {
    "$date": "2023-03-14T14:25:07.187Z"
  },
  "__v": 0,
  "githubMember": [
    {
      "$oid": "641effa7f79a140014a47a3b"
    }
  ],
}

```

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [August 29, 2023, 12:52pm UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/19 "2023-08-29T12:52:49Z")

</div>

Your issue is on your data. Valeri is badly written, it should have

```javascript
"githubMember": {
  "$oid": "641effa7f79a140014a47a3b"
}

```

instead of

```javascript
"githubMember": [
    {
      "$oid": "641effa7f79a140014a47a3b"
    }
  ]

```

---

<div class="post-metadata">

**Author:** ![XavierColombel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/xaviercolombel/32/106_2.png) [@XavierColombel](https://community.forestadmin.com/u/XavierColombel)\
**Post date:** [August 29, 2023, 1:29pm UTC](https://community.forestadmin.com/t/search-doesnt-return-anything/6573/20 "2023-08-29T13:29:27Z")

</div>

> [@anon62739609](#):
>
> ```javascript
> [
> {
> "$oid": "641effa7f79a140014a47a3b"
> }
> ]
> 
> ```

@anon62739609 thank you very much for pointing out this hudge mistake by our side. But it’s still totally weird because it worked until theses days. Anyway, I’ve updated our model. 💪🙏
