相关文章推荐
飘逸的饭卡  ·  进程监控工具supervisor ...·  22 小时前    · 
老实的绿茶  ·  PYTHON | ...·  1 年前    · 
坐怀不乱的乌冬面  ·  python ...·  1 年前    · 
玩篮球的松鼠  ·  直播 SDK ...·  1 年前    · 
失恋的稀饭  ·  windows - Console ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm new to MongoDB and I've been religiously slogging through the Beginners' guide to using MongoDB 2.2 and the official C# driver http://www.codeproject.com/Articles/524602/Beginners-guide-to-using-MongoDB-and-the-offic

Everything seems to be going well, except I'm not sure how to handle a MongoDB Null value

This is my data structure

public class DataStructure
    public ObjectId _id { get; set; }
    public DateTime CreatedOn { get; set; }
    public DateTime UpdatedOn { get; set; }
    public string ClaimId { get; set; }
    public string Status { get; set; }
    public string FmcCity { get; set; }
    public string FmcState { get; set; }
    public Int32 TestType { get; set; }
    public List<LineItemStructure> LineItems { get; set; }
public class LineItemStructure
    public string LineItemDescription { get; set; }
    public string LineItemType { get; set; }
    public string PartNumber { get; set; }
    public double LaborHours { get; set; }
    public double Quantity { get; set; }

And this is the code which connects to the MongoDB and pulls back values, until it encounters a null field value and returns the error below

       var client = new MongoClient(connectionString);
       MongoServer server = client.GetServer();
       var database = server.GetDatabase("FleetClaims");
      MongoCollection< DataStructure> collection = database.GetCollection< DataStructure >("Claims");
        //Execute the query
        MongoCursor< DataStructure> results = collection.FindAll();
  

"An error occurred while deserializing the LineItems property of class ...: An error occurred while deserializing the LaborHours property of class ... : Cannot deserialize Double from BsonType Null."

Can anyone suggest a reference or different approach to handle the nulls? Will BsonString.Empty help me here?

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.