0

I have a data with array in mongodb collection

"data": [
         [
           "FA3T1",
           16
         ]
       ]

Can anyone please suggest what would be the datatype to be mentioned in c# for the data to get deserialized.

I have tried the below options but it doesnt seem to work

List<object> data {get;set;}

or

ArrayList data {get;set;}
3
  • What do you mean by "does not seem to work"? Do you get an error or is data null? Commented Jul 26, 2022 at 7:46
  • It seems the data type is List<List<object>>. Commented Jul 26, 2022 at 8:56
  • Hi @Markus Thanks for responding I get the following error Cannot deserialize a 'Int32' from BsonType 'Array'.", Commented Jul 26, 2022 at 9:36

1 Answer 1

1

List<List<object>> should work:

        public class Entity
        {
            public List<List<object>> data { get; set; }
        }

        var document = BsonDocument.Parse($@"
        {{
            data : [ [ 'FA3T1', 16 ] ]
        }}");
        var result = BsonSerializer.Deserialize<Entity>(document);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.