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.
A query of
{foo: undefined}produces different results in sharedb-mongo and sharedb-mingo-memory:foounset orfoo: null.foocondition were not present. Any other query conditions are still applied.Cause
parseQueryusesJSON.stringify->JSON.parseto do a deep clone of the query:https://github.com/share/sharedb-mingo-memory/blob/v1.1.0/index.js#L88
However,
JSON.stringifyignores fields with values ofundefined, 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
undefineddown to the Mongo driver. Both the official mongodb driver and mingo handle values ofundefinedby converting them tonull.Potential fixes
Either switch
parseQueryto do a proper structured deep clone, or just do a shallow clone if that's sufficient.