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

Strange schema behavior with sub-sub-index #590

Closed
Feverqwe opened this issue Mar 29, 2018 · 0 comments
Closed

Strange schema behavior with sub-sub-index #590

Feverqwe opened this issue Mar 29, 2018 · 0 comments

Comments

@Feverqwe
Copy link

Feverqwe commented Mar 29, 2018

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
            }
          }
        },
      },
    }
  }
};
@Feverqwe Feverqwe changed the title Strange scheme behavior with sub-sub-index Strange schema behavior with sub-sub-index Mar 29, 2018
@pubkey pubkey closed this as completed in 1b44b63 Mar 29, 2018
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

1 participant