-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
A query of {foo: undefined} produces different results in sharedb-mongo and sharedb-mingo-memory:
- In sharedb-mongo, it matches docs that either have
foounset orfoo: null. - In sharedb-mongo, it matches all docs, as if the
foocondition 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.
Metadata
Metadata
Assignees
Labels
No labels