apache / apache/grails-core

Join data is missing when aggregate lookup is performed using Grails Domain in GORM for Mongo

Open
#14,393 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-mongodb
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Task List

- [ ] Steps to reproduce provided
- [ ] Stacktrace (if present) provided
- [ ] Example that reproduces the problem uploaded to Github
- [ ] Full description of the issue provided (see below)

### Steps to Reproduce

1. Create a Test MongoDB.

2. Create a Grails Domain called Order with static mapWith = "mongo", BSON ObjectId id, Long orderId, (any other fields you desire) List orderItems and relationship static hasMany = [orderItems: OrderItem]

3. Create another Grails Domain called OrderItem with static mapWith = "mongo", , BSON ObjectId id, Long orderId, (any other fields that you desire) and relationship static belongsTo = [Order]

4. Create up a simple controller, view, service etc in Grails and hook it up.

5. Populate some data in your Mongo Collections such that order.orderItems -> orderItem.id

6. In a Service method call:
Order.aggregate( [
Aggregates.lookup("orderitem", "orderItems", "_id", "orderItems")
] )
and observe the output for orderItems: [] is empty.

7. In a Service method call:
Order.collection.aggregate( [
Aggregates.lookup("orderitem", "orderItems", "_id", "orderItems")
] ).toList()
and observe the output for orderItems: [ ... ] has proper data.

### Expected Behaviour

When doing aggregate lookups, the lookup should return the join data.

### Actual Behaviour

Join data is missing when aggregate lookup is performed using Grails Domain. Using the underlying collection to do aggregate lookup, join data is available.

### Environment Information

- **Operating System**: Win10
- **GORM Version:** 7.0.0
- **Grails Version (if using Grails):** 4.0.0
- **JDK Version:** 1.8

Contributor guide

Open the contributing guide

Research direction

Start with the Grails service calls using Order.aggregate and Order.collection.aggregate, then compare how GORM for Mongo maps the aggregation result for the Order and OrderItem domains. Reproduce the issue with the documented relationships and lookup against the orderitem collection. Done means the domain aggregate returns the same joined orderItems data as the underlying collection aggregate.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, mongodb
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.