Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8660535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:16:34+00:00 2026-06-12T16:16:34+00:00

Let’s say this is a collection of 2 Bson documents { _id: …, name:

  • 0

Let’s say this is a collection of 2 Bson documents

{
    "_id": "...",
    "name": "Test1",
    "sub": {
        "street": "134 Fake Street",
        "city": "NoWhere"
    }
},
{
    "_id": "...",
    "name": "Test2",
    "sub": {
        "height": "10",
        "width": "20",
        "sub2": {
            "type": "something"
        }
    }
}

where the first level is a structured class but sub-levels can be completely unstructured and can have further nested documents several levels deep.

How can I deserialize this document to a C# class? All samples I have seen assume some structure in nested documents.

The following class gives an error:

public class Report
{
    [BsonId]
    public ObjectId _id { get; set; }

    public string name { get; set; }

    public BsonDocument sub { get; set; }
}

Type ‘MongoDB.Bson.BsonString’ with data contract name ‘…’ is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

EDIT

What I’m trying to do might be complete non-sense. Is it a better idea to just use one BsonDocument and handle everything manually without a structured class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:16:35+00:00Added an answer on June 12, 2026 at 4:16 pm

    I don’t think the error message you are getting is from the C# driver. Can you please provide a stack trace?

    I’ve tried to reproduce your issue but it works fine with my test program.

    The document inserted by the above test program looks like this:

    > db.test.find()
    { "_id" : ObjectId("5075fc6ee447ad1354c1f018"), "name" : "John Doe", "sub" : { "x" : 1, "y" : 2 } }
    >
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString
Let's say I've got a collection of 10 million documents that look something like
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say after I had login I will be prompt to enter the Name
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say, if I need to assign an id to element with first name,
Let's say I have some text as follows: do this, do that, then this,
Let's say an Owner has a collection of Watch(es). I am trying to create
let's say I have a select list as follows: <select name='languages'> <option value='german'>German</option> <option

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.