2

I'm trying to store an object in the document. This is my entity:

public Guid Id { get; set; } 
public string CreatedBy { get; set; } 
public string CreatedByIp { get; set; } 
public DateTime CreatedAt { get; set; }  
public string LastUpdatedBy { get; set; } 
public string LastUpdatedByIp { get; set; } 
public DateTime? LastUpdatedAt { get; set; }
public object LastContext { get; set; } 

LastContext object that contains multiple properties must be stored in the document, but this is what is stored in the document:

enter image description here

Also, because of the architecture, I should not use MongoDB attributes for entity properties.

6
  • Have you tried to convert :LastContext" to an Json object and store that in the MongoDB? I had a similar issue and converting it to Json object stored it the right way for me. Commented Apr 5, 2022 at 8:40
  • @SimpForJS Do you mean to use JsonConvert.SerializeObject? Commented Apr 5, 2022 at 9:19
  • Not really. I used JObject class if I remember correctly. Commented Apr 5, 2022 at 12:30
  • @SimpForJS I can not use this method due to architecture Commented Apr 6, 2022 at 7:21
  • This should work for you: stackoverflow.com/questions/47510650/… Commented Apr 6, 2022 at 11:32

1 Answer 1

2

You can map your class to another class with same properties with JObject or JToken type , which can be stored in Mongo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.