Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid reference when using group on lookup pipeline #4647

Closed
ghimisradu opened this issue Feb 22, 2024 · 2 comments
Closed

Invalid reference when using group on lookup pipeline #4647

ghimisradu opened this issue Feb 22, 2024 · 2 comments
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged

Comments

@ghimisradu
Copy link

Running a lookup with pipeline and including an group stage results in invalid reference for the group id field:
org.springframework.dao.InvalidDataAccessApiUsageException: Invalid reference 'myField'

Aggregation.lookup()
    .from('my-collection')
    .let(ExpressionVariable.newVariable("variable").forField("$myObject.field"))
    .pipeline(
        Aggregation.match(Expr.valueOf(Eq.valueOf("$myField").equalTo("$$variable"))),
        Aggregation.group("$myField")
    )
    .as("myObjects")

Running the same stage in mongo shell returns the correct results.

{
  "$lookup": {
      "from": "my-collection",
      "let": {
          "variable": "$myObject.field"
      },
      "pipeline": [{
              "$match": {
                  "$expr": {
                      "$eq": ["$myField", "$$variable"]
                  }
              }
          }, {
              "$group": {
                  "_id": "$myField"
              }
          }
      ],
      "as": "myObjects"
  }
}

The objects from target collection my-collection look like this:

{
  _id: ObjectId,
  myField: String,
  _class: String
}

If I remove the group field reference the stage works, but of course wrong results will be returned

  • Spring boot version: 3.1.3
  • Spring data mongodb version: 4.1.3
  • Reactive driver version: 4.9.1
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 22, 2024
@christophstrobl
Copy link
Member

@ghimisradu Thank you for getting in touch. It would be great if you could take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem so we can also see the domain types involved and how to aggregation is triggered.

@christophstrobl christophstrobl added the status: waiting-for-feedback We need additional information before we can continue label Feb 29, 2024
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants