[v4 beta] A tag's `children` join is always empty: documents tagged with `createTagField` never show up

Open
#18,814 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@lazerg is already working on this.

Since Oct 17, 2026.

  • #18819 by @lazerg — open
  • #18821 by @CloudCorpRecords — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
mongodb, nodejs, typescript
Domain
backend, database

Research direction

Start with packages/db-mongodb/src/utilities/buildJoinAggregation.ts, especially the multi-collection join comparison described around line 141, and reproduce using pnpm repro:join-limit with the supplied MongoDB setup. Verify the behavior through the tag edit drawer and the REST join query; the change is complete when children.docs includes documents whose tag field contains the queried ID, including multi-value arrays, without regressing the limit: 0 behavior covered separately.

Written by the indexing model from the issue text.

Description

Bug created-by: Contributor db: mongodb
Describe the Bug

What you see: the post "Hello" is tagged with "News". The News page in the admin lists it, but the News tag's own children field shows "No Results." The REST API and Local API return the same: children.docs is [].

Expected: the children join of a tag lists the documents tagged with it, here the post.

Clicking News in the Tags list: the post "Hello" is listed Opening News with the cog: children shows "No Results."
Browse view of News lists Hello Edit drawer of News shows No Results

When it happens: the join spans more than one collection (the hierarchy children join always does: tags and posts) and the linking field holds several values. createTagField holds several values by default, so every tagged document is missing.

Why: for joins over several collections, buildJoinAggregation.ts L141 matches with

{ $expr: { $eq: [`$${join.field.on}`, '$$root_id_'] } }

This compares the whole stored array (_h_tags: [newsId, sportId]) to a single id, so it is never equal. Joins over one collection use localField/foreignField (L400-L402), which does find an id inside an array.

Related: #18812 is a different bug in the same function (limit: 0 crashes). This one also happens with a normal limit like 5.

Link to the code that reproduces this issue

https://github.com/AaronClaes/payload-v4-hierarchy-repro

Reproduction Steps

Needs a local MongoDB.

  1. Clone the repo, then run cp .env.example .env and pnpm install.
  2. Run pnpm repro:join-limit. This creates the tags "News" and "Sport", and a post "Hello" tagged with both.
  3. Run REPRO_JOIN_LIMIT=10 pnpm dev, open /admin and create a user. (The higher join limit avoids #18812.)
  4. Go to Tags and click News. The page lists the post "Hello" under Posts, so the tag link exists.
  5. Click the cog icon next to the "News" title to edit the tag. In the drawer, the children field shows "No Results." It should list "Hello".

The REST API shows the same: /api/tags?joins[children][limit]=5&where[name][equals]=News returns children.docs: [].

Which area(s) are affected?

db: mongodb

Environment Info
Binaries:
  Node: 24.15.0
  pnpm: 10.17.1
Relevant Packages:
  payload: 4.0.0-beta.2
  next: 16.4.2
  @payloadcms/db-mongodb: 4.0.0-beta.2
  @payloadcms/ui: 4.0.0-beta.2
  react: 19.3.1
  react-dom: 19.3.1
Database: MongoDB 8.3.7
Operating System:
  Platform: darwin (arm64)
Dominant language
TypeScript
Stars
45.6k
Forks
4.4k
Avg merge
1d 16h
Merged PRs (30d)
285

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 payloadcms/payload

All issues in payloadcms/payload

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.