Reputation: 4472
I am trying to convert a BsonString to BsonArray as follows:
BsonString str = "[{ \"_id\" : \"domain\", \"nm\" : \"Domain\", \"value\" : [\"test.com\"], \"dt\" : ISODate(\"2014-08-04T04:00:00Z\") }]\"";
BsonArray array = str.AsBsonArray;
And I get exception:
Unable to cast object of type 'MongoDB.Bson.BsonString' to type 'MongoDB.Bson.BsonArray'.
Any ideas on how can I parse a string to a BsonArray object. Without doing it by hand?
Upvotes: 0
Views: 2287
Reputation: 4472
Some mucking around, and found the solution
BsonArray array = BsonSerializer.Deserialize<BsonArray>(str);
Upvotes: 4