MongoDB and C#: "ReadString cannot be called when BsonType is: ObjectId"
{"ReadString cannot be called when BsonType is: ObjectId"} was the error I received a few times while learning MongoDB.
I was getting this often until I saw a posting on Google Groups which reminded me that we need to be type conscious. I was setting the “_id” type to string. Realize that it needs to be set to ObjectId (which is a MongoDB C# driver type).
1: public class Thing
2: {3: public Thing() { }
4: public string Id { get; set; }
5: public string author { get; set; }
6: public string title { get;set; }
7: }Change line #4 from “string” to “ObjectId” and you’re set.
| Related Posts | Print This Post |


Hi, I'm Vikram Pant. 



