-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution_013.cs
39 lines (34 loc) · 1.07 KB
/
Solution_013.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using MongoDB.Bson;
using MongoDB.Driver;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace MongoDBConsoleApp.Solutions
{
internal class Solution_013 : ISolution
{
public void Run(IMongoClient _client)
{
IMongoDatabase _database = _client.GetDatabase("demo");
var collection = _database.GetCollection<BsonDocument>("person");
string name = "rob";
var pipeline = new BsonDocument[]
{
new BsonDocument("$match",
new BsonDocument
{
{ "name", BsonRegularExpression.Create(new Regex(name, RegexOptions.IgnoreCase)) }
}
)
};
var result = collection
.Aggregate<BsonDocument>(pipeline)
.ToList();
Helpers.PrintFormattedJson(result);
}
public async Task RunAsync(IMongoClient _client)
{
await Task.Run(() => Run(_client));
}
}
}