Skip to content

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

Open
@ericyhwang

Description

@ericyhwang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions