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

SimpleMongoRepository.findById(id, class) don't return ids for nested documents.

    XMLWordPrintable

    Details

      Description

      SimpleMongoRepository.findById(id, class) don't return ids for nested documents.

      E.g.

      class A {
       private String id; //stored in mongo as "id"
       private String name;
      }
      
      class B {
        private String id; // stored in mongo as "_id"
        private List<A> innerDocs;
      }
      

      When it return B documents, innerDocs A objects have id == null. If i refactor A.id to A.myId, then it start working correctly.

      Saving data (save, updateFirst, etc) always save fields correctly.

      A and B objects are pojos (only lombok @Data and @NoArgsConstructor is used to provide getters and setters). Ids are created by mongo.

      Could it related somehow to ids that have 24 characters, but stored not as "_id"?

      Easy workaround is to have different field name (not "id").

        Attachments

          Activity

            People

            Assignee:
            cstrobl Christoph Strobl
            Reporter:
            system Konstantin Petrukhnov
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: