share / share/sharedb-mingo-memory

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

Open
#9 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5
Forks
9
Avg merge
3h 1m
Merged PRs (30d)
3

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 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at parseQuery in index.js around line 88 and reproduce a query containing {foo: undefined} against the in-memory adapter. Preserve the undefined field during cloning so its handling matches sharedb-mongo and mingo, then verify that the field condition is applied while other query conditions still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.