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

$sort when field data is NULL #608

Open
MariaCamilaCubides opened this issue Jul 13, 2021 · 4 comments
Open

$sort when field data is NULL #608

MariaCamilaCubides opened this issue Jul 13, 2021 · 4 comments

Comments

@MariaCamilaCubides
Copy link

MariaCamilaCubides commented Jul 13, 2021

Description

Hello, guys. I am making a query to the store filter by an array of ids and sorting by a specific field, but it doesn't matter if I sort ASC or DES the NULL value is always at the first position of the result.

The array of devicesIds is [ "a1732fb5-dca7-4895-a668-eacca0c10fb9", "361ce725-a5dc-4e43-ae73-a29a2ac0eec7" ]
And the last user of those Ids are the following:

  • "a1732fb5-dca7-4895-a668-eacca0c10fb9" --> lastUser = NULL // If lastUser is an empty string it works.
  • "361ce725-a5dc-4e43-ae73-a29a2ac0eec7" --> lastUser = 'user'
    The query for the store is:
...mapGetters('devices', { findDevicesInStore: 'find' }),
const devices = this.findDevicesInStore({
        query: {
          companyId: this.currentCompany.id,
          id: {
            $in: devicesIds,
          },
          $limit: 1,
          $sort: {  lastUser: 1  },  // also tested with { lastUser: -1 }
        },
 });

Expected behavior

The result will be the data of the device with ID "361ce725-a5dc-4e43-ae73-a29a2ac0eec7"

Actual behavior

The actual result is the data of the device with ID "a1732fb5-dca7-4895-a668-eacca0c10fb9"

System configuration

feathers-vuex: 3.16.0

@J3m5
Copy link
Contributor

J3m5 commented Jul 14, 2021

Hello.
Sorting is handled by the @feathers/adapter-commons package which use the sort algorithm of the NeDb package.

Maybe you should try to ask in the feathers repository.

@marshallswain
Copy link
Member

@MariaCamilaCubides you may have already created a workaround for this. If you could provide a small sample data set for which this fails, or even better would be a failing test example, then I can look into it.

@MariaCamilaCubides
Copy link
Author

Hello @marshallswain.
I found the origin of the issue. Null values are grouped by default at the beginning or ending according to the database, however, databases such as PostgreSQL allow you to set the position of the nulls. The sort doesn't work well because the API returns the nulls at the beginning and feathers-vuex returns the nulls at the end so when I use the pagination the results from the API and the store were different. I did a PR trying to solve this feathersjs-ecosystem/feathers-sequelize#370

@marshallswain
Copy link
Member

@MariaCamilaCubides it looks like the PR got merged. Can this issue be closed?

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

3 participants