spring-projects / spring-projects/spring-data-mongodb

MongoCommandException while using of $all in aggregation

Open
#3,762 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: feedback-provided
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Structure of documents:

{
  id: ObjectId("5ef1cd704b35c6d6698f2050")
  date: 2021-12-15T11:03:00.000+00:00
  priorityList: Array
    0: "any-String-id-here"
    1: ...
}

Using of $all in Aggregation:

TypedAggregation<MyDocument> aggregation = newAggregation(MyDocument.class,
  project("id")
    .and("isInList").applyCondition(ConditionalOperators
        .when(Criteria.where("priorityList").all("here-my-string-to-check"))
        .then(1)
        .otherwise(0)),
  sort(Sort.by(
    Sort.Order.desc("isInList"),
    Sort.Order.desc("date"))));
mongoTemplate.aggregate(aggregation, "my-collection-name", String.class);

produces

com.mongodb.MongoCommandException: 
Command failed with error 168 (InvalidPipelineOperator): 'Invalid $project ::
caused by :: Unrecognized expression '$all''

Contributor guide

Open the contributing guide

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 by reproducing the shown TypedAggregation with Criteria, ConditionalOperators, and mongoTemplate.aggregate against MongoDB. Trace how the $all condition is rendered inside the project stage, then verify that the reported InvalidPipelineOperator no longer occurs for the example aggregation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb, spring
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.