本文整理汇总了C#中MongoDB.Driver.MongoClient.GetCollection方法的典型用法代码示例。如果您正苦于以下问题:C# MongoClient.GetCollection方法的具体用法?C# MongoClient.GetCollection怎么用?C# MongoClient.GetCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.MongoClient
的用法示例。
在下文中一共展示了MongoClient.GetCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Any
public void Any(KnockPostV1 request)
{
var db = new MongoClient().GetDatabase("test");
var collection = db.GetCollection<Potato>("KnockKnock");
collection.FindOneAndReplace(Builders<Potato>.Filter.Eq(k => k.Id, request.Knock.Id), new Potato(request.Knock),
new FindOneAndReplaceOptions<Potato, Potato>() { IsUpsert = true });
}
示例2: Aggregate_with_query
public void Aggregate_with_query()
{
var startDate = GetStartDate();
var endDate = GetEndDate();
var duration = new TimeSpan(endDate.Ticks - startDate.Ticks);
var maxCount = duration.TotalMinutes / delta.TotalMinutes;
var stopWatch = new Stopwatch();
var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce");
var sessions = dataBase.GetCollection<Session>("Sessions");
stopWatch.Start();
var statistic = new List<StatisticItem>();
for (int i = 0; i < maxCount; i++)
{
var startStroke = startDate.AddMinutes(delta.Minutes * i);
var endStroke = startStroke.AddMinutes(delta.Minutes);
statistic.Add(this.GetStatisticItem(startStroke, endStroke, sessions));
}
stopWatch.Stop();
foreach (var statItem in statistic)
{
Trace.WriteLine(statItem.DateTime + " " + statItem.Count);
}
Trace.WriteLine("Aggregation: " + stopWatch.ElapsedTicks);
}
示例3: Aggregate_with_map_reduce
public void Aggregate_with_map_reduce()
{
var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce");
var sessions = dataBase.GetCollection<Session>("Sessions");
BsonJavaScript map = new BsonJavaScript(Scipts.map);
BsonJavaScript reduce = new BsonJavaScript(Scipts.reduce);
var result = sessions.MapReduce(map, reduce);
}
示例4: RequestResponsePairQueryService
public RequestResponsePairQueryService(IConfig config)
{
var url = MongoUrl.Create(config.ProxyDbConnectionString);
var db = new MongoClient(url)
.GetServer()
.GetDatabase(url.DatabaseName);
_collection = db.GetCollection<RequestResponsePair>();
}
示例5: MongoDBRevisionStorage
public MongoDBRevisionStorage(string connectionString)
{
ConnectionString = connectionString;
var mongoUrl = MongoUrl.Create(connectionString);
var database = new MongoClient(mongoUrl).GetDatabase(mongoUrl.DatabaseName);
_revisions = database.GetCollection<RevisionModel>("revisions");
}
示例6: UseCaseQueryService
public UseCaseQueryService(IConfig config)
{
var url = MongoUrl.Create(config.ProxyDbConnectionString);
var db = new MongoClient(url)
.GetServer()
.GetDatabase(url.DatabaseName);
_collection = db.GetCollection<UseCase>();
}
示例7: UseCaseUpdateTask
public UseCaseUpdateTask(IConfig config, IDataList<UseCase> useCases)
{
var url = new MongoUrl(config.ProxyDbConnectionString);
var db = new MongoClient(url)
.GetServer()
.GetDatabase(url.DatabaseName);
_collection = db.GetCollection<UseCase>("UseCase");
_useCases = useCases;
}
示例8: MongoDBUserStorage
public MongoDBUserStorage(string connectionString)
{
ConnectionString = connectionString;
var mongoUrl = MongoUrl.Create(connectionString);
var database = new MongoClient(mongoUrl).GetDatabase(mongoUrl.DatabaseName);
_users = database.GetCollection<UserModel>("users");
Task.Run(() => SetUp()).Wait();
}
示例9: Aggregate
public void Aggregate()
{
var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce");
var collection = dataBase.GetCollection<Session>("Sessions");
var match = GetMatchOperator(GetStartDate(), GetEndDate());
var project = GetProjectOperator(GetStartDate());
var pipeline = new[] { match, project };
var result = collection.Aggregate(pipeline);
var matching = result.ResultDocuments.Count();
}
示例10: AddMessage
public static void AddMessage(string username, string text)
{
MongoDatabase db = new MongoClient("mongodb://daniel:[email protected]:61548/chat-db")
.GetServer()
.GetDatabase("chat-db");
var messagesCollection = db.GetCollection<Message>("messages");
var message = new Message { Date = DateTime.Now, Username = username, Text = text };
messagesCollection.Insert(message);
}
示例11: mainAsync
public static async Task mainAsync()
{
var db = new MongoClient().GetDatabase("school");
var collection = db.GetCollection<BsonDocument>("students");
var list = await collection.Find(new BsonDocument()).ToListAsync();
var newList = new List<BsonDocument>();
list.ForEach(data => newList.Add(dropScore(data)));
await db.DropCollectionAsync("students");
await db.CreateCollectionAsync("students");
await collection.InsertManyAsync(newList);
}
示例12: MainAsync
static async Task MainAsync()
{
var database = new MongoClient().GetDatabase("students");
var collection = database.GetCollection<BsonDocument>("grades");
List<BsonDocument> listStudents = await collection.Find(new BsonDocument("type", "homework")).ToListAsync();
listStudents.GroupBy(data => data["student_id"]).Select(data => new { student_id = data.Key, score = data.Min(x => x["score"]) }).ToList().ForEach(student =>
{
Console.WriteLine(student + " score removed.");
collection.DeleteOneAsync(new BsonDocument("student_id", student.student_id).Add("score", student.score).Add("type", "homework"));
});
}
示例13: TableFiller
public TableFiller(DbSettings configuration)
{
Configurations = configuration.collections.Configurations;
Counters = configuration.collections.Counters;
ConnectionString = configuration.connectionstring;
DatabaseName = configuration.database;
Database = new MongoClient(ConnectionString).GetServer().GetDatabase(DatabaseName);
var configJson = Database.GetCollection(Configurations).FindOne().ToJson();
Config = JsonConvert.DeserializeObject<Configurations>(configJson);
}
示例14: PrintAllMessages
public static void PrintAllMessages()
{
MongoDatabase db = new MongoClient("mongodb://daniel:[email protected]:61548/chat-db")
.GetServer()
.GetDatabase("chat-db");
var messagesCollection = db.GetCollection<Message>("messages");
var messages = messagesCollection.FindAll();
foreach (var message in messages)
{
Console.WriteLine("Message:\n User:{0}\n Text: {1}", message.Username, message.Text);
Console.WriteLine();
}
}
示例15: Main
static void Main()
{
var db = new MongoClient(Connections.Default.MongoCloud).GetServer().GetDatabase("mongochat");
var messages = db.GetCollection<BsonDocument>("Messages");
Console.Write("Username: ");
string username = Console.ReadLine();
while (true)
{
Console.Write("> ");
string input = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(input))
messages.Insert(
new BsonDocument { { "Author", username }, { "Text", input }, { "Time", DateTime.Now } });
var formattedMessages = messages
.FindAll()
.Select(m => string.Format("[{0}] {1}: {2}", m["Time"].ToLocalTime(), m["Author"], m["Text"]));
Console.WriteLine(string.Join(Environment.NewLine, formattedMessages));
}
}