mongo-adapter: $type 'array' does not match a field that is an array

Open
#43,325 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@mrityunjay-pandey is already working on this.

Since Oct 30, 2026.

  • #43326 by @mrityunjay-pandey — open
  • #43389 by @sudoKrishna — open

Assessment

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

Research direction

Start at the createPredicateFromFilter entry point in @rocket.chat/mongo-adapter and check how $type: 'array' handles arrays and their elements. Reproduce the issue with the provided examples, including an empty array, and compare the results with the stated MongoDB behavior. Done means both ordinary and empty arrays match while nested arrays continue to behave consistently with MongoDB.

Written by the indexing model from the issue text.

Description

type: bug
Description:

In @rocket.chat/mongo-adapter (the client-side filter used for local collections), $type: 'array' (or $type: 4) does not match a field that is itself an array. The filter skips the array and only checks its elements, so it matches only arrays nested inside arrays.

MongoDB (3.6 and later) matches any array with { field: { $type: 'array' } }, including an empty one, so the same filter selects different documents on the client and on the server.

Steps to reproduce:
import { createPredicateFromFilter } from '@rocket.chat/mongo-adapter';

const isArray = createPredicateFromFilter({ foo: { $type: 'array' } });
isArray({ foo: [1, 2] }); // false
isArray({ foo: [] }); // false
isArray({ foo: [[1]] }); // true
Expected behavior:

isArray({ foo: [1, 2] }) and isArray({ foo: [] }) return true, as in MongoDB.

Actual behavior:

Both return false.

Server Setup Information:
  • Version of Rocket.Chat Server: develop (69a52ce39b)
Dominant language
TypeScript
Stars
46.5k
Forks
14.1k
Avg merge
1d 21h
Merged PRs (30d)
381

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

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.

More from RocketChat/Rocket.Chat

All issues in RocketChat/Rocket.Chat

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.