Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1571

Map to nested elements

    XMLWordPrintable

    Details

      Description

      As per question on SO: http://stackoverflow.com/questions/35362675/mongodb-map-class-from-nested-elements-in-c-sharp

      When creating a class map in the BsonClassMap class, I would like to be able to reference nested elements.

      e.g.

      BsonClassMap.RegisterClassMap<RestaurantAddress>(map =>
      {
          map.MapMember(c => c.Id).SetElementName(("_id"));
          map.MapMember(c => c.Building).SetElementName("address.building");
          map.MapMember(c => c.Street).SetElementName("address.street");
          map.MapMember(c => c.ZipCode).SetElementName("address.zipcode");
      });
      

      For a document like:

      {
          "_id" : ObjectId("56bb82621ff72e0d9ba267cb"),
          "address" : {
              "building" : "6409",
              "coord" : [ 
                  -74.005289, 
                  40.628886
              ],
              "street" : "11 Avenue",
              "zipcode" : "11219"
          },
          "borough" : "Brooklyn",
          "cuisine" : "American ",
          "grades" : [ 
              {
                  "date" : ISODate("2014-07-18T00:00:00.000Z"),
                  "grade" : "A",
                  "score" : 12
              }, 
              {
                  "date" : ISODate("2013-07-30T00:00:00.000Z"),
                  "grade" : "A",
                  "score" : 12
              }
          ],
          "name" : "Regina Caterers",
          "restaurant_id" : "40356649"
      }
      

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: