Skip to content

Strange schema behavior with sub-sub-index #590

Description

@Feverqwe

Case

Schema with sub-sub-index

Issue

Uncaught (in promise) RxError: RxError:
SchemaCheck: given index is not defined in schema
Given parameters: {
key:"fileInfo.watch.time"}
    at Object.exports.newRxError (webpack:///./node_modules/rxdb/src/rx-error.js?:107:63)
    at reduce.filter.map.key (webpack:///./node_modules/rxdb/src/plugins/schema-check.js?:246:37)
    at Array.map (native)
    at checkSchema (webpack:///./node_modules/rxdb/src/plugins/schema-check.js?:243:6)
    at HOOKS.(anonymous function).forEach.fun (webpack:///./node_modules/rxdb/src/hooks.js?:69:33)
    at Array.forEach (<anonymous>)
    at runPluginHooks (webpack:///./node_modules/rxdb/src/hooks.js?:69:18)
    at Object.create (webpack:///./node_modules/rxdb/src/rx-schema.js?:300:54)
    at RxDatabase.collection (webpack:///./node_modules/rxdb/src/rx-database.js?:264:93)
    at Promise.resolve.then (webpack:///./src/js/bg/library2/rx.js?:512:28)

Info

  • Environment: electron
  • Adapter: IndexedDB
  • Stack: React

Code

async () => {
  const schema = {
    name: 'items',
    schema: {
      version: 0,
      type: 'object',
      properties: {
        id: {
          type: 'string',
          primary: true
        },
        fileInfo: {
          type: 'object',
          properties: {
            watch: {
              type: 'object',
              properties: {
                time: {
                  type: 'number',
                  index: true
                }
              }
            }
          },
        },
      }
    }
  };

  const db = await RxDB.create({
    name: 'testdb',
    adapter: 'idb',
    multiInstance: false
  });

  const col = await db.collection(schema);

  await col.insert({ id: '1', fileInfo: { watch: { time: 1 } } });

  // -99.. next one bug, in code added fix for integer, here is number type
  return col.find().where('fileInfo.watch.time').gt(-9999999999999999999999999999).sort('fileInfo.watch.time').exec();
}

If change schema to this it works fine.

const schema = {
  name: 'items',
  schema: {
    version: 0,
    type: 'object',
    properties: {
      id: {
        type: 'string',
        primary: true
      },
      fileInfo: {
        type: 'object',
        properties: {
          watch: {
            time: {
              type: 'number',
              index: true
            }
          }
        },
      },
    }
  }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions