Can Atlas Search be used from the C# driver?

Can this feature be used from the C# driver?

Hi @Graeme_Henderson,

Yes, Atlas search queries take the form of an aggregation pipeline stage $seachBeta. For example:

var pipeline = new BsonDocument[] 
{
    new BsonDocument ( "$searchBeta", new BsonDocument(
      "search", new BsonDocument(
          "query", "foobar").Add("path", "field")
           ).Add(
       "highlight", new BsonDocument(
           "path", "field")
        )
    )
};
var aggregation = collection.Aggregate<BsonDocument>(pipeline);

Note that you can also build aggregation pipeline using MongoDB Compass and then Export Pipeline to Specific Programming Language i.e. C# to help you build the aggregation pipeline.

See also Tutorial: Build a Movie Search Engine Using Atlas Full-Text Search in 10 Minutes

Regards,
Wan.

1 Like

An engineer on our team recently wrote an extension of our C# driver specifically for Atlas Search. It’s really great.

3 Likes

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