Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-2237

The _id field is flatted out in the aggregation results

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 2.1.5 (Lovelace SR5)
    • Fix Version/s: None
    • Component/s: Mapping / Conversion
    • Labels:

      Description

      Hi everyone!

      Reproducible test case: https://github.com/darrachequesne/spring-data-mongodb-demo

      When using the following aggregation:

      Price priceFromAggregation = mongoTemplate.aggregate(newAggregation(
            match(where("_id.productId").is(1))
      ), Price.class, Price.class).getMappedResults().get(0);
      

      The id field in the Price object is null.

      It seems the UnwrapAndReadDocumentCallback (here: https://github.com/spring-projects/spring-data-mongodb/blob/2.2.0.M2/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java#L2084) is flattening the _id field in the raw results.

      // raw
      { _id: { productId: 1, storeId: 1 }, other fields... }
      // mapped to
      { productId: 1, storeId: 1, other fields... }
      

       Is that the expected behaviour?

      Thanks!

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              cstrobl Christoph Strobl
              Reporter:
              darrachequesne Damien Arrachequesne
              Last updater:
              Mark Paluch
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: