Is there a Driver for mongodb to use Atlas search in .net core application?

Viewed 875

I'm using MongoDB Atlas in my .net core application, using c# driver to connect the database, recently came to know about Atlas Search and I'm able to create an index for my collections, Is there a way to use $searchbeta from my application to query my index?

2 Answers

You can use the aggregate method and BsonDocument.Parse:

var pipeline = BsonDocument.Parse("{ $searchBeta: { search: { path: 'foo', query : 'bar' } }}");
var result = col.Aggregate<BsonDocument>(pipeline);

You can use Aggregation Pipeline

For c# driver see Pipelines section in the Definitions and Builders docs

var pipeline = new BsonDocument[] 
{
    BsonDocument.Parse("{ $searchBeta: ... }"),
    BsonDocument.Parse("{ $sort: ... }")
};
var result = _db.GetCollection<Person>("people").Aggregate<Person>(pipeline).ToList();
Related