rxdb: count() is incorrect

In our web app, we do this:

const rxQuery = collection.count({
    selector: {
      id: {
        $eq: 'persistentStateBlob',
      },
    },
  });
const result = await.exec();

Expected: result is 0. Actual: result is 1.

In fact, if I use the following code instead…

const rxQuery = collection.find({
    selector: {
      id: {
        $eq: 'persistentStateBlob',
      },
    },
  });
const result = (await.exec()).length;

result is 0. (That’s the exact same query)

Data

The collection does contain one item with an ID of persistentStateBlob2.

Schema

{
    primaryKey: 'id',
    properties: {
        id: { type: 'string', maxLength: 100 },
        value: { type: 'string' },
    },
    required: ['value'],
    type: 'object',
    version: 0,
}

Versions and storage

  • rxdb: 14.11.1
  • rxdb-premium: 14.11.1
  • storage: premium IndexedDB storage via shared storage worker

What I’ve tried

### With our app

  • Chromium and Firefox browsers.
  • Disabling eventReduce.
  • Disabling multiInstance.
  • Removing the key compression plugin (this collection doesn’t use it anyway).
  • Disabling the shared storage worker wrapper.
  • Using the memory storage (without the shared storage worker).
  • Deleting the IndexedDB databases in browser devtools.

All behave the same.

RxDB tests

  • I created a test in test/unit/bug-report.test.ts and ran it with node+dexie; it passed.
  • I changed the count matching only test in test/unit/rx-collection.test.ts and ran it with node+dexie; it passed.

Other notes

  • count(...) (with a selector) correctly returns 0 if the collection is empty.
  • count() without any argument seems correct.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 20 (18 by maintainers)

Commits related to this issue

Most upvoted comments

Looks good, thanks

Test: https://github.com/pubkey/rxdb/pull/4843. Interestingly when I run this test locally, the .exec call fails and the .$.subscribe call works. The opposite of what I saw last in our Cypress tests.

This is still an issue as far as I know. I can’t today but I’ll test again with the latest version when I get a chance