[GH-ISSUE #14] Exception with filters #14

Closed
opened 2026-05-23 08:25:22 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @clibu on GitHub (Feb 28, 2021).
Original GitHub issue: https://github.com/appy-one/acebase/issues/14

Originally assigned to: @appy-one on GitHub.

Running the following query

db.query('songs')
    .filter('year', '==', 2014)                     // uses the index on year
    .filter('genre', 'in', ['jazz','rock','blues']) // uses the index on genre
    .get();

where there is a match on filter( year but no match on filter( genre does:

Using indexes for query: /songs/*/year, /songs/*/genre
(node:54336) UnhandledPromiseRejectionWarning: Error: TypeError: Cannot read property 'value' of undefined
    at C:\webapps\play2\AceBase\node_modules\acebase-core\dist\data-reference.js:795:19

If I change filter( genre so it does match a doc in 2014 it works as expected.

It doesn't matter whether indexes are used or not.

Originally created by @clibu on GitHub (Feb 28, 2021). Original GitHub issue: https://github.com/appy-one/acebase/issues/14 Originally assigned to: @appy-one on GitHub. Running the following query ```` db.query('songs') .filter('year', '==', 2014) // uses the index on year .filter('genre', 'in', ['jazz','rock','blues']) // uses the index on genre .get(); ```` where there is a match on ``filter( year`` but no match on ``filter( genre`` does: ```` Using indexes for query: /songs/*/year, /songs/*/genre (node:54336) UnhandledPromiseRejectionWarning: Error: TypeError: Cannot read property 'value' of undefined at C:\webapps\play2\AceBase\node_modules\acebase-core\dist\data-reference.js:795:19 ```` If I change ``filter( genre`` so it does match a doc in 2014 it works as expected. It doesn't matter whether indexes are used or not.
gitea-mirror 2026-05-23 08:25:22 -06:00
Author
Owner

@appy-one commented on GitHub (Mar 2, 2021):

I was able to reproduce when adding the indexes on year and genre fields. Test code:

const { AceBase } = require('acebase');
const db = new AceBase('test');

async function test() {
    await db.ready();

    // Setup test data
    await db.ref('songs').remove();
    await db.ref('songs').push({ title: 'Some 2014 blues song', year: 2014, genre: 'blues' });
    await db.ref('songs').push({ title: 'Some 2014 rock song', year: 2014, genre: 'rock' });
    await db.ref('songs').push({ title: 'Some 2014 jazz song', year: 2014, genre: 'jazz' });
    await db.ref('songs').push({ title: 'Some 2014 funk song', year: 2014, genre: 'funk' });
    await db.ref('songs').push({ title: 'Some 2014 dance song', year: 2014, genre: 'dance' });

    await db.ref('songs').push({ title: 'Another 2010 blues song', year: 2010, genre: 'blues' });
    await db.ref('songs').push({ title: 'Another 2010 rock song', year: 2010, genre: 'rock' });
    await db.ref('songs').push({ title: 'Another 2010 jazz song', year: 2010, genre: 'jazz' });
    await db.ref('songs').push({ title: 'Another 2010 funk song', year: 2010, genre: 'funk' });
    await db.ref('songs').push({ title: 'Another 2010 dance song', year: 2010, genre: 'dance' });

    // Setup indexes
    await db.indexes.create('songs', 'year');
    await db.indexes.create('songs', 'genre');

    // Query
    const snaps = await db.query('songs')
        .filter('year', '==', 2014)
        .filter('genre', 'in', ['jazz','rock','blues'])
        .get(); // <-- UnhandledPromiseRejectionWarning: Error: TypeError: Cannot read property 'value' of undefined

    console.log(snaps.getValues());
}
test();

I've found what's causing this issue and will fix it asap

<!-- gh-comment-id:788730101 --> @appy-one commented on GitHub (Mar 2, 2021): I was able to reproduce when adding the indexes on year and genre fields. Test code: ```js const { AceBase } = require('acebase'); const db = new AceBase('test'); async function test() { await db.ready(); // Setup test data await db.ref('songs').remove(); await db.ref('songs').push({ title: 'Some 2014 blues song', year: 2014, genre: 'blues' }); await db.ref('songs').push({ title: 'Some 2014 rock song', year: 2014, genre: 'rock' }); await db.ref('songs').push({ title: 'Some 2014 jazz song', year: 2014, genre: 'jazz' }); await db.ref('songs').push({ title: 'Some 2014 funk song', year: 2014, genre: 'funk' }); await db.ref('songs').push({ title: 'Some 2014 dance song', year: 2014, genre: 'dance' }); await db.ref('songs').push({ title: 'Another 2010 blues song', year: 2010, genre: 'blues' }); await db.ref('songs').push({ title: 'Another 2010 rock song', year: 2010, genre: 'rock' }); await db.ref('songs').push({ title: 'Another 2010 jazz song', year: 2010, genre: 'jazz' }); await db.ref('songs').push({ title: 'Another 2010 funk song', year: 2010, genre: 'funk' }); await db.ref('songs').push({ title: 'Another 2010 dance song', year: 2010, genre: 'dance' }); // Setup indexes await db.indexes.create('songs', 'year'); await db.indexes.create('songs', 'genre'); // Query const snaps = await db.query('songs') .filter('year', '==', 2014) .filter('genre', 'in', ['jazz','rock','blues']) .get(); // <-- UnhandledPromiseRejectionWarning: Error: TypeError: Cannot read property 'value' of undefined console.log(snaps.getValues()); } test(); ``` I've found what's causing this issue and will fix it asap
Author
Owner

@appy-one commented on GitHub (Mar 2, 2021):

Published fix in version 1.1.1, let me know if it works.

<!-- gh-comment-id:788753459 --> @appy-one commented on GitHub (Mar 2, 2021): Published fix in version 1.1.1, let me know if it works.
Author
Owner

@clibu commented on GitHub (Mar 3, 2021):

@appy-one Yes fixed. Thanks for the prompt resolution.

<!-- gh-comment-id:789498682 --> @clibu commented on GitHub (Mar 3, 2021): @appy-one Yes fixed. Thanks for the prompt resolution.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase#14
No description provided.