Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在我的 .net 核心应用程序中使用 MongoDB Atlas,使用 c# 驱动程序连接数据库,最近了解了 Atlas Search,我能够为我的集合创建索引,有没有办法使用 $searchbeta from我的应用程序来查询我的索引?
您可以使用该aggregate方法和BsonDocument.Parse:
aggregate
BsonDocument.Parse
var pipeline = BsonDocument.Parse("{ $searchBeta: { search: { path: 'foo', query : 'bar' } }}"); var result = col.Aggregate<BsonDocument>(pipeline);
您可以使用聚合管道
对于 c# 驱动程序,请参阅定义和构建器文档中的管道部分
var pipeline = new BsonDocument[] { BsonDocument.Parse("{ $searchBeta: ... }"), BsonDocument.Parse("{ $sort: ... }") }; var result = _db.GetCollection<Person>("people").Aggregate<Person>(pipeline).ToList();