Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested query not working #1365

Open
Gyurmatag opened this issue Dec 4, 2024 · 1 comment
Open

Nested query not working #1365

Gyurmatag opened this issue Dec 4, 2024 · 1 comment

Comments

@Gyurmatag
Copy link

I want to filter for the nationalities in the "launches" query like this:

{
    query: nationality ? { "payloads.nationalities": nationality } : {},
     options: {
         sort: { "date_utc": "desc" },
         page,
         limit,
        populate: ["payloads"],
      },
},

But this gives me no items back... There is a 2 year old issue where others also couldn't solve this.
Probably this might be a bug inside the backend, maybe here:

// Query launches
router.post('/query', cache(20), async (ctx) => {
  const { query = {}, options = {} } = await transformQuery(ctx.request.body);
  try {
    const result = await Launch.paginate(query, options);
    ctx.status = 200;
    ctx.body = await transformResponse(result);
  } catch (error) {
    ctx.throw(400, error.message);
  }
});

or somewhere in the _transform-query.js file

Does anybody has any idea on this? How we can solve it?

Thank you very much!

@sandyastronaut777
Copy link

Hi @Gyurmatag
I encountered the same issue and found that the query isn't returning results when trying to filter by payloads.nationalities as expected.

After testing, I used the query structure like this:

{ "query": nationality ? { "payloads.nationalities": { $in: [nationality] } } : {}, "options": { "sort": { "date_utc": -1 }, "page": 1, "limit": 10, "populate": ["payloads"] } }
However, even with this structure, no results were returned.

A possible reason could be that the payloads.nationalities field is an array, and there might be issues when querying for a single value without checking for the array structure properly. Also, date_utc sorting may be another issue, depending on how the data is formatted and stored.

I recommend:
Test the query without sorting to check if the issue is with the sorting logic:
{ "query": nationality ? { "payloads.nationalities": { $in: [nationality] } } : {}, "options": { "page": 1, "limit": 10, "populate": ["payloads"] } }
Check for valid data in the payloads.nationalities field. Ensure that the array contains the correct nationality format and matches the query.
It might also help to review the backend query logic where Launch.paginate is invoked, as there could be issues with how the query is transformed and passed to MongoDB.
Also, you may have a look over following screenshots...I queried for sample data.

Screenshot 2024-12-14 at 12 36 17 PM Screenshot 2024-12-14 at 12 41 52 PM Screenshot 2024-12-14 at 12 42 03 PM Screenshot 2024-12-14 at 12 42 18 PM Screenshot 2024-12-14 at 12 42 39 PM Screenshot 2024-12-14 at 12 43 06 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants