pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.37k stars 1.04k forks source link

Error: Cannot sort on field(s) "XXX" when using the default index #157

Closed matsuo-ts closed 7 years ago

matsuo-ts commented 7 years ago

Case

Bug on find() and findOne()

Issue

@pubkey As I reported in #154 , after updating to 4.0.0 , error occurring in collection query.

Error: Cannot sort on field(s) "XXX" when using the default index
    at validateSort (bundle.js:165)
    at bundle.js:165
(anonymous) @ bundle.js:244

This error does not happen in version 3.0.2. Maybe this comes form PouchDB

Info

Code

RxDB.create({
      name: DB_NAME,
      password: PASSWORD,
      adapter: 'websql'
    })
    .then( db => {
      return db.collection({
        name: COLLECTION_NAME,
        schema: COLLECTION_SCHEMA
      });
    })
    .then( collection => {
      collection
        .findOne( KEY1 )
        .where( KEY2 )
        .eq( VALUE )
        .exec()
        .then( result => {
          if ( result === null ) {
            // CODE FOR TRUE
          }
          else {
           // CODE FOR FALSE
         }
        })
        .catch( err => {
          console.error( 'Failed to open collection: ', err );
        });
    })
    .catch( err => {
      console.error( 'Failed to open Database: ', err );
    });
pubkey commented 7 years ago

Is it possible to post your schema? This would help very much to reproduce.

matsuo-ts commented 7 years ago

@pubkey Sorry for less information. Here is my schema for this collection.

export const COLLECTION_SCHEMA = {
  'disableKeyCompression': true,
  'title': 'User Preferences',
  'version': 0,
  'description': 'DESCRIPTION',
  'type': 'object',
  'properties': {
    'user_id': {
      'type': 'string',
      'primary': true
    },
    'user_pwd': {
      'type': 'string',
      'encrypted': true
    },
    'last_login': {
      'type': 'number'
    },
    'status': { 
      'type': 'string'
    }
  },
  'required': [ 'user_pwd', 'last_login', 'status' ]
};

I use 'last_loginasKEY1, 'status as KEY2.

pubkey commented 7 years ago

@matsuo-ts I was able to reproduce the error, but my current solution breaks something else.