Filter value from BsonDocument (dynamic field) in C#

BsonDocument filtration does not work as expected. I need to filter BsonDocument (I used the BsonDocument field to store JSON object). I need to filter using that json property.

As a example

public class Book
        public string Id { get; set; }

        public string Author { get; set; }

        public BsonDocument Metadata { get; set; }

below json save in Metadata field (BsonDocument)

   "name":"John 2",

now I need to filter using name or age field. how can I do that in .net core ? any idea or support

Seems like this is working. let me know if anyone know better solution than this
_books.Find(Builders.Filter.Eq(“”, “Test User”)).ToList()

1 Like

It seems you could also try

var filter = Builders.Filter.Eq(“fieldName.nestedFieldName”, “value”)

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.