-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Incorrect data returned in find functions #66
Comments
Hi @MMJM |
Here is a sample bit of code The first FindOne should return testValue = 0 You will notice the _rev value output is the same which is not correct. I deleted the original rev and added a new entry. As I mentioned above I think the issue stems from RxCollection _createDocument A modification in that function to this seems to return what I want.
As I don't know the side effects of doing this on your _docCache you would know if this is enough. ` const bugSchema = {
` |
Hi @pubkey That looks like it describes the problem to me. A lot tidier than my code :( I really need to get on to the Await stuff However the same thing can happen if you use INSERT instead of UPSERT for the second document revision. It would seem that just tidying up in the upsert will not cover all cases hence my original suggestion of the cleanup in the _createDocument function. |
I've not looked into why but using the original rxdb code and running upsert then upsert without the delete does return the correct revision |
I also added a test with insert -> remove -> insert I published version 3.0.1 to npm. Please try it out and close this if fixed |
@pubkey Looks good. Many thanks. |
There appears to be an issue with the data being returned in the Find. What is returned does not match what comes out of the PouchDB Find functions.
It would appear that the issue stems from RxCollection _createDocument
My issue is this.
I have the following document in PouchDB
{ _id: 'abc', _rev:'1' }
Call RxDocument.remove() and the data would become this.
{ _id: 'abc', _rev:'1', _deleted: true}
Now add a new document with the same Primary
{ _id: 'abc', _rev:'2'}
Run a Find query and you will see that the data will probably as in my case have this entry
{ _id: 'abc', _rev:'1', _deleted: true}
Which is not what the PouchDB Find returned.
As I said I think the issue stems from RxCollection _createDocument
In here _rev 1 is stored in _docCache for Primary abc
When the code checks the cache for the primary from the PouchDB find it matches and returns the entry in _docCache being _rev 1 and not _rev 2 which was returned from PouchDB.
I think there needs to be a check on the _rev key and not just the Primary.
Perhaps something like this is enough.
if (cacheDoc && cacheDoc._rev == json["_rev"]) return cacheDoc;
Does that make any sense?
The text was updated successfully, but these errors were encountered: