Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4429

Updates push/addToSet Does Not Add Discriminator to Subdocuments

    • Type: Icon: New Feature New Feature
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Builders

      Summary

      Updates push/addToSet Does Not Add Discriminator to Subdocuments

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      org.mongodb:mongodb-driver-sync:4.2.3

      Mongo 4.4.10 running on Atlas

      How to Reproduce

      Say if we have the following objects:

      public class HDUser {
      
        private ObjectId id;
      
        private List<Content> contents;
      }
      @BsonDiscriminator(value="Content", key="_cls")
      public class Content {
        private ObjectId id;
        private Metadata metadata;
      }
      
      @BsonDiscriminator(value="Metadata", key="_cls")
      public class Metadata {
        private String name;
        private Long size;
      }

      If I add a Content with Metadata to an existing HDUser, I expect that Metadata to have a field called "_cls: Metadata" however, I do not see that. Content would have its BsonDiscriminator, but not the subdocument (metadata) within it.

      This is what I ran to add the content

      Content c = new Content(...)
      Bson addContent = Updates.addToSet("content", c);
      Bson updateContentOrder = Updates.addToSet("content_order", c.getId());
      return userCollection.updateOne(eq("_id", uid), Updates.combine(addContent, updateContentOrder));
      

       

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            mizw2010@gmail.com Mingze Wang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: