C# driver and scoreDetails


Am I correct in assuming that it is not possible yet to use the (relatively) newly released “scoreDetails” feature with the C# driver?

And secondly when it will be available, I assume that setting the bool would work the same as the implemented “returnStoredSource” feature and the projectionBuilder would get a “metaSearchScoreDetails” ?

Thanks in advance,


Hi @sboulema - Welcome to the community :wave:

I have the following code snippet which was run in my test environment (using C# driver version 2.19.0):

static void Main(string[] args)
            var uri = "<REDACTED>";
            var mongoURL = new MongoUrl(uri);
            var client = new MongoClient(mongoURL);
            var database = client.GetDatabase("lamp");            
            var collection = database.GetCollection<BsonDocument>("collection");

          	var pipeline = new BsonDocument[]
                new BsonDocument("$search", 
                new BsonDocument
                        { "index", "default" }, 
                        { "autocomplete", 
                new BsonDocument
                            { "query", "lamp" }, 
                            { "path", "name" }
                        } }, 
                        { "scoreDetails", true }
                new BsonDocument("$project", 
                new BsonDocument
                        { "_id", 0 }, 
                        { "name", 1 }, 
                        { "scoreDetails", 
                new BsonDocument("$meta", "searchScoreDetails") }
           	var result = collection.Aggregate<BsonDocument>(pipeline).ToList();

            foreach (var document in result)


Which provides the following output (cut short for brevity but you can see the scoreDetails field in the output):

{ "name" : "floor lamp", "scoreDetails" : { "value" : 2.0917689800262451, "description" : "sum of:", "details" : [{ "value" : 1.0077003240585327, "description" : "$type:autocomplete/name:lamp [BM25Similarity], result of:" ...

Hoping my above example helps but regarding this question, do you have an example of how you’re performing the search with "returnStoredSource" so I can assist better here.

Look forward to hearing from you.


1 Like

Thanks for the reply!

My current code looks like this:

        var results = await _carsCollection
                indexName: "searchFacets",
                searchDefinition: Builders<CarModel>.Search
                returnStoredSource: true

I am using the AggregateFluent interface and that has a nice parameter to easily give the returnStoredSource boolean. I was hoping for a similar way of specifying the scoreDetails boolean.

Found this related ticket: MongoDB Jira. Which gives a way to do the projection part.

Created a Jira ticket for this: https://jira.mongodb.org/browse/CSHARP-4703

I am currently working a PR that would implement this :slight_smile:

1 Like

Added PR! CSHARP-4703: Initial implementation by sboulema · Pull Request #1126 · mongodb/mongo-csharp-driver · GitHub

1 Like

Thanks Samir - I believe the appropriate drivers team will need to check into the PR / ticket raised. I would recommend following the tickets in the mean time for any updates.


PR has been merged, so this should be available in an upcoming release :slight_smile:

1 Like

Thanks Samir! I’ll mark your reply with the CSHARP ticket link as the solution so that it can be monitored :slight_smile:


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