Simple.Data.MongoDB icon indicating copy to clipboard operation
Simple.Data.MongoDB copied to clipboard

Embedded array problem

Open pbagh opened this issue 11 years ago • 1 comments

Hi,

Updating a document containing array types seems to be broken. Initial insertion works as expected but when the document is updated the array type is no longer stored in its original form. The update stores additional type information for the array member (_t System.Int32[]) which causes subsequent retrievals to return null for the array type.

Sample:

using System; using System.Collections.Generic; using System.Dynamic; using System.Linq; using System.Text; using System.Threading.Tasks;

using Simple.Data; using Simple.Data.MongoDB; using MongoDB.Bson;

namespace ConsoleApplication1 { class Program { class TestArray { public string Id { get; set; } public int[] Ints { get; set; } }

    static void Main(string[] args)
    {
        dynamic db = Database.Opener.OpenMongo("mongodb://fn101devz01/Test");

        TestArray test_array =
            new TestArray
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Ints = new int[] { 0, 1, 2 }
            };

        db.Test.Insert(test_array);
        test_array = db.Test.All().First();
        // Causes additional type info to be stored
        db.Test.Update(test_array);
        // Array member is null
        test_array = db.Test.All().First();
    }
}

}

Thanks,

Patrick

pbagh avatar Mar 20 '13 21:03 pbagh

I'll take a look and see what I come up with...

craiggwilson avatar Mar 23 '13 21:03 craiggwilson