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

Update.PushEachWrapped wrap data in a wrong way adding data to a sub array

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 1.8, 1.8.1, 1.8.2
    • None
    • .net 4.0
    • Fully Compatible

    Description

      This command:

      var builder = Update.PushEachWrapped("ArrayData", new List<GenericListItem>
      {
      new GenericListItem()

      { Name = "name", Surname = "surname" }
      });


      It is translated in :

      { "$push" : { "ArrayData" : { "$each" : [[{ "Name" : "name", "Surname" : "surname" }]] } } }

      that is wrong, due to a [ in sub elements.

      The right command translation has to be

      { "$push" : { "ArrayData" : { "$each" : [{ "Name" : "name", "Surname" : "surname" }] } } }

      otherwise a sub array will be created.


      The same problem is also present in :
      PushAllWrapped
      AddToSetEachWrapped
      PushEachWrapped

      There is a possible workaround forcing the conversion between IEnumerable<T> to Array. So re-writing the above code in this way

      var builder = Update.PushEachWrapped("ArrayData", new List<GenericListItem>
      {
      new GenericListItem()
      { Name = "name", Surname = "surname" }

      }.ToArray());

      create a correct serialization.

      It seems that the problem is located here in UpdateBuilder.cs

      BsonDocumentWrapper.CreateMultiple(values).Cast<BsonValue>();
      (public UpdateBuilder PushEachWrapped<T> ... raw 1309 in UpdateBuilder.cs) wrap each values in an array

      Attachments

        Activity

          People

            Unassigned Unassigned
            lucacasali Luca casali
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: