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

Same query producing a different result? #698

Closed
devfelipereis opened this issue Jun 25, 2018 · 7 comments
Closed

Same query producing a different result? #698

devfelipereis opened this issue Jun 25, 2018 · 7 comments

Comments

@devfelipereis
Copy link

Case

BUG

Issue

Same query producing a different result.

Info

  • Environment: Ionic 3
  • Adapter: IndexedDB
  • Stack: Typescript, Angular, Ionic

@ionic/app-scripts : 3.1.8
Cordova Platforms : android 7.0.0
Ionic Framework : ionic-angular 3.9.2

"pouchdb-adapter-http": "^6.4.3"
"pouchdb-adapter-idb": "^6.4.3"
"rxdb": "^7.4.4"
"rxjs": "5.5.8"

Code

  db.collections['post']
      .find({
        $and: [
          { event_id: { $eq: 2 } },
          { user_id: { $eq: '6' } },
          { created_at: { $gt: null } },
        ],
      })
      .sort({ created_at: 'desc' })
      .exec().then(data => console.log(data));
 db.collections['post']
      .find().where('event_id').eq(2).where('user_id').eq('6').where('created_at').gt(null)
      .sort({ created_at: 'desc' })
      .exec().then(data => console.log(data));

I'm new with rxdb but I think that this queries do the same thing, right?

In the first query I also get results that "event_id" is equals 1. In the second query this does't happen.
Any ideia?

@pubkey
Copy link
Owner

pubkey commented Jun 25, 2018

Your queries are correct. This looks like a bug. Can you submit a failing PR to reproduce this? You can start by editing this file: https://github.com/pubkey/rxdb/blob/master/test/unit/bug-report.test.js

pubkey added a commit that referenced this issue Jun 25, 2018
@pubkey
Copy link
Owner

pubkey commented Jun 25, 2018

I could not reproduce this with the attached test. Please reopen this with a reproducing test-case

@pubkey pubkey closed this as completed Jun 25, 2018
@gvuyk
Copy link
Contributor

gvuyk commented Jul 5, 2018

I've been tracking this bug/feature? for a little while now and I think I found it.
When you make 2 equal queries, the second just returns the cached results from the first (that is, if the cache wasn't invalidated by an insert or something else), now, if you alter the results array from the first query, the second returns the same altered results

How to reproduce

docs = await collection.find({}).exec()    // docs.length == x
docs.splice(0, 1);                         // docs.length == x-1
docs = await collection.find({}).exec()    // docs.length == x-1

Is this your case @devfelipereis?

@pubkey
Copy link
Owner

pubkey commented Jul 5, 2018

@gvuyk that might be the case. I think exec() then should always return a new array to prevent this.

@pubkey pubkey reopened this Jul 5, 2018
@devfelipereis
Copy link
Author

devfelipereis commented Jul 5, 2018

Hello. Sorry for being late...
@gvuyk @pubkey Look at this:

Results
screenshot from 2018-07-05 10 51 36

Look that in _data object, event_id is 1. In my query I'm looking for 2.

Post schema

{
  "title": "post schema",
  "description": "describes a post",
  "version": 0,
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "primary": true
    },
    "event_id": {
      "type": "number"
    },
    "user_id": {
      "type": "string",
      "ref": "user"
    },
    "text": {
      "type": "string"
    },
    "photo": {
      "type": ["string", "null"]
    },
    "created_at": {
      "type": "string",
      "index": true
    },
    "likes_count": {
      "type": "number"
    },
    "comments_count": {
      "type": "integer"
    },
    "user": {
      "type": "object",
      "properties": {
        "data": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "photo": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}

EDIT

I close the app after posting this. Then I open again to do another test. Now I'm not getting that results.

image

@pubkey
Copy link
Owner

pubkey commented Jul 6, 2018

@devfelipereis have you enabled the query-change-detection?

@pubkey pubkey closed this as completed in 6c72b1a Jul 6, 2018
@pubkey
Copy link
Owner

pubkey commented Jul 6, 2018

@gvuyk I fixed the problem with mutating result-arrays.
@devfelipereis Please create a test, screenshots do not really help. I believe you that there is a problem, you do not have to create further evidence. We need something that I can use to reproduce and fix this.

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

3 participants