Jan 25

{"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 Print This Post

  • Leave a Reply

     

     

    preload preload preload
    © 2010 Vikram Pant       All Opinions Are My Own And Not That Of My Employer(s)       Site Powered By WordPress   Theme is Pageline's iBlog2