0
votes

How to deserialize BSon Element "ISODate" to "string".

e.g. { "_id" : ObjectId("57c2e34ccaefdc0cbe14d614"), "ID" : "1", "Demand" : [ { "assignmentId" : "100", "commonDemandId" : "1000", "createDttm" : ISODate("2016-08-28T00:00:00.000Z") } ] } .

In this BSON Document createDttm has ISODate. What I am doing : var JSS = new JavaScriptSerializer(); var rec = JSS.Deserialize(records[p]);

But this is showing Invalid JSON primitive: ISODate. Please provide with a solution.Have used Json.net also. But not working.Any solution would be hoghly appreciated. Thanks.

1
record[p] gives the value present in the e.g. above.bsk

1 Answers

0
votes

I am not able to understand your question. You can just do a toString() to Date value.

How Data is loaded

You can get the details of the CreatedDate by just this kind of code.

IMongoClient _client = new MongoClient("********************");
IMongoDatabase _database = _client.GetDatabase("***");
IMongoCollection<BsonDocument> _collection = _database.GetCollection<BsonDocument>("********");
var filter = Builders<BsonDocument>.Filter.Eq("Add", 1);
var test = _collection.Find(filter).ToList();

var createdtest = test[0]["CreatedDate"].ToString();

Console.WriteLine(createdtest);

Don't know I was not able to answer your question.