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

  • SEARCH
  • Home
  • 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 9195693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:41:04+00:00 2026-06-17T21:41:04+00:00

I have a document with sub-documents and sub-sub-documents { ClockID : fd51b6e0-5b81-49ab-8424-71fd768281b2, ClockName :

  • 0

I have a document with sub-documents and sub-sub-documents

{
 "ClockID" : "fd51b6e0-5b81-49ab-8424-71fd768281b2",
 "ClockName" : "AAA-TEST123-002",
 "FilesList" : [{
                 "FileName" : "AAA-TEST123-002.mpg",
                 "FileLocationHistory" :    [{
                                               "FullPath" : "192.168.32.166/Ingestion",
                                               "AllowDeleteOnCancel" : false,
                                               "_id" : "565b7343-9dc5-4916-a788-0f392fce2502"
                                    }],
                  "_id" : "15b54499-a0be-4278-82ed-58c82c13bd40",
               }],
 "_id" : ObjectId("510164d0a63cfa2250fd6d19"),
 "_t" : "ClockRecord"

This is mapped to 3 classes:

public class ClockRecord : IDatabaseRecord
{
      public ClockRecord()
      {
         FilesList = new List<ClockRecordFile>();
      }
      public string ClockID { get; set; }
      public string ClockName { get; set; }        
      public List<ClockRecordFile> FilesList { get; set; }
      public BsonObjectId _id { get; set; }
}

public class ClockRecordFile
{
     public ClockFileRecord()
     {
         FileLocationHistory = new List<ClockFileLocationHistoryRecord>();
     }
     public string FileName { get; set; }
     public string FileStatus { get; set; }
     public string _id { get; set; }
 }

public class ClockFileLocationHistoryRecord
{
    public string FullPath { get; set; }
    public bool AllowDeleteOnCancel { get; set; }
    public string _id { get; set; }
}

And I use this method to retrieve the top level document:

public List<ClockRecord> GetClocksByID(string id)
{
   var collection = MongoDatabase.GetCollection<ClockRecord>(Collections.Clocks);
   var query = from e in collection.AsQueryable()
            where e._id == ObjectId.Parse(id) 
             select e;

   var clocks = query.ToList();
   return clocks;
}

So,
when I want to update a sub-document in the FilesList array I use this:

    public void UpdateClocksFilesRecord(string collectionName, ClockFileRecord clockFileRecord, BsonObjectId clockDocumentID)
    {
        var mongoCollection = MongoDatabase.GetCollection<ClockRecord>("Clocks");
        var update = Update.Set("FilesList.$", BsonDocumentWrapper.Create<ClockFileRecord>(clockFileRecord));
        var modeResult = mongoCollection.Update(
                Query.And(
                Query.EQ("_id", clockDocumentID),
                Query.ElemMatch("FilesList", Query.EQ("_id", clockFileRecord._id))
                ),
                update, UpdateFlags.Upsert
                );
    }

This works fine.

When I want to update a sub-sub-document in the FilesList.FileLocationHistory array I use this:

    public void UpdateClockFilesLocationRecord(string collectionName, ClockFileLocationHistoryRecord clockFileLocationHistory, BsonObjectId clockDocumentID, string clockFileDocumentID)
    {
        var mongoCollection = MongoDatabase.GetCollection<ClockRecord>("Clocks");
        var update = Update.Set("FilesList.$.FileLocationHistory", BsonDocumentWrapper.Create<ClockFileLocationHistoryRecord>(clockFileLocationHistory));
        var modeResult = mongoCollection.Update(
             Query.And(
                Query.EQ("_id", clockDocumentID),
                Query.EQ("FilesList._id", clockFileDocumentID)
                ), 
              update, UpdateFlags.Upsert
              );
    }

This updates the sub-sub-document OK but when I run GetClocksByID() to deserialise the document I get an error:

“An error occurred while deserializing the FilesList property of class ClockRecord:

An error occurred while deserializing the FileLocationHistory property of class ClockFileRecord:

Expected element name to be ‘_t’, not FullPath.”

Now the FileLocationHistory document did not have a property _t before the edit and it de-serialized just fine (the top level document does have _t).

Why is the driver expecting the document to have an _t property after the update?
And what should I do about it?

Additional:
The only change I can see is that the FileLocationHistory document changes the order of fields after the update. I don’t know if this relevant.

  • 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-17T21:41:05+00:00Added an answer on June 17, 2026 at 9:41 pm

    OK, the problem is that my Update code is turning FileLocationHistory from an array of documents into an object.
    I have posted this as a new question:

    “Why does my Update to a sub document remove the array nature of sub document”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory with multiple sub directories that contain .doc files. Example: C:\Users\tmedina\Documents\testenviroment\Released\500\test0.doc
I have a class Document (in a mongodb collection) and persist various sub classes
My JSON documents (called i), have sub documents (called elements). I am looping trhough
In Open office I have created a macro for printing documents. sub printDoc(FileName) Dim
I have a document and a embedded document using MongoEngine class Sub(EmbeddedDocument): Id =
If I have a MongoDB collection with documents and sub-documents, as illustrated: And, if
We have had the unenviable happen: various master documents refer to sub-documents that are
Basically what we have here Getting the headings from a Word document Public Sub
I have a document-based Cocoa application that has to start up a sub-process before
I have a class, Document and several sub-classes ( Invoice , PurchaseOrder , etc).

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.