feathersjs-ecosystem / feathers-vuex

Integration of FeathersJS, Vue, and Nuxt for the artisan developer

Home Page:https://vuex.feathersjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

$sort when field data is NULL

MariaCamilaCubides opened this issue · comments

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

commented

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.

@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.

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

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