1

I'm using my .net6.0 api, this model:

public class Tournament
{
    public List<ObjectId> FriendsId { get; set; }

is serialized as:

{"FriendsId":[{"timestamp":1654717093,"machine":540378,"pid":-19594,"increment":6387934,"creationTime":"2022-06-08T19:38:13Z"},...

but I want to have a string representation like this:

{"FriendsId":[{"62a0f94f185b87a1a88c2354"},...

what is the right way to obtain this result? my wish is to have a string rapresentation in json, keeping a list of objectid in the mongo entity.

1 Answer 1

2

You should change the model like this adding the following attribute:

[BsonRepresentation(BsonType.ObjectId)]
public List<string> Friends { get; set; } = new  List<string>();
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.