-
Notifications
You must be signed in to change notification settings - Fork 64
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
Two queries by nested fields return duplicated result #79
Comments
Thanks for reporting! What version? This may have been fixed in |
"_id": "[email protected]" |
I'm unable to reproduce—I added a passing test case that I think does what you said? apollo-datasource-mongodb/src/__tests__/datasource.test.js Lines 132 to 136 in 08e1c07
If you could modify/add a test case that demonstrates the bug, that would be a big help |
Hello, Please check diff with my forked version here: master...potpe:apollo-datasource-mongodb:filtering-with-nested-fields The issue only happens when underlying DataLoader library batches multiple invocations of findByFields method together and when fields provided are nested fields. Consider following documents to be present in MongoDb:
findByFields invocations as follows:
These get optimized into a single Mongo query like this:
Results from Mongo are returned and are matching all documents at this stage:
2 problems happen in a) call to Due to this, all docs from the result are attached to all 3 items in fieldsArray, effectively causing duplication.
b) even if the above call returned correct value, call to Branch in my forked version is trying to fix these 2 issues. Expected content of orderedDocs would be as follows:
Hopefully the above makes sense, but let me know if anything needed any further clarification. |
Hi @lorensr ! Could you please look at the above findings and the proposed fix? Thank you! |
A PR would be great, thanks! |
So there is a document
{ "top-field": "abc", "nested-fields": { "field1": "value", "field2": "" } }
I'm sending two queries:
const itemsA = this.findByFields({ "nested-fields.field1": "value"}); const itemsB = this.findByFields({ "nested-fields.field2": "value"});
itemsB contains data, but shouldn't.
The issue, as I realized, comes from cache.js orderDocs and getNestedValue method.
It processes correctly filters like { nested-fields: { field1: "value" }}, but cannot process concatenated fields.
The text was updated successfully, but these errors were encountered: