【发布时间】:2020-02-29 09:25:15
【问题描述】:
我在我的 .net 核心应用程序中使用 MongoDB Atlas,使用 c# 驱动程序连接数据库,最近了解了 Atlas Search,我能够为我的集合创建索引,有没有办法使用$searchbeta 从我的应用程序中查询我的索引?
【问题讨论】:
标签: mongodb mongodb-.net-driver mongodb-atlas mongodb-atlas-search
我在我的 .net 核心应用程序中使用 MongoDB Atlas,使用 c# 驱动程序连接数据库,最近了解了 Atlas Search,我能够为我的集合创建索引,有没有办法使用$searchbeta 从我的应用程序中查询我的索引?
【问题讨论】:
标签: mongodb mongodb-.net-driver mongodb-atlas mongodb-atlas-search
你可以使用aggregate方法和BsonDocument.Parse:
var pipeline = BsonDocument.Parse("{ $searchBeta: { search: { path: 'foo', query : 'bar' } }}");
var result = col.Aggregate<BsonDocument>(pipeline);
【讨论】:
您可以使用Aggregation Pipeline
对于 c# 驱动程序,请参阅 Definitions and Builders 文档中的管道部分
var pipeline = new BsonDocument[]
{
BsonDocument.Parse("{ $searchBeta: ... }"),
BsonDocument.Parse("{ $sort: ... }")
};
var result = _db.GetCollection<Person>("people").Aggregate<Person>(pipeline).ToList();
【讨论】: