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

In queries, fields with undefined value are not included in final filter #9

Open
ericyhwang opened this issue May 14, 2019 · 0 comments

Comments

@ericyhwang
Copy link
Contributor

A query of {foo: undefined} produces different results in sharedb-mongo and sharedb-mingo-memory:

  • In sharedb-mongo, it matches docs that either have foo unset or foo: null.
  • In sharedb-mongo, it matches all docs, as if the foo condition were not present. Any other query conditions are still applied.

Cause

parseQuery uses JSON.stringify -> JSON.parse to do a deep clone of the query:
https://github.com/share/sharedb-mingo-memory/blob/v1.1.0/index.js#L88

However, JSON.stringify ignores fields with values of undefined, which aren't valid in strict JSON. For example, JSON.stringify({foo: undefined}) produces {}.

This does not match the behavior of sharedb-mongo, which passes values of undefined down to the Mongo driver. Both the official mongodb driver and mingo handle values of undefined by converting them to null.

Potential fixes

Either switch parseQuery to do a proper structured deep clone, or just do a shallow clone if that's sufficient.

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

1 participant