With Async/Await
static void Main(string[] args)
{
Method1(args).Wait();
Console.ReadLine();
}
static async Task Method1(string[] args)
{
var conString = "mongodb://localhost:27017";
var Client = new MongoClient(conString);
var DB = Client.GetDatabase("local");
var collection = DB.GetCollection<BsonDocument>("TeraData");
var Filter = new BsonDocument("TransactionId", "123");
var list = collection.Find(Filter).ToListAsync();
foreach (var dc in await list)
{
// Console.WriteLine(dc);
}
}
----------------------
Without async/await
public string GetSessionData(string transactionID)
{
try
{
connectionString = ConfigurationManager.AppSettings[mongoConnKey];
mongoDatabase = ConfigurationManager.AppSettings[mongodb];
var client = new MongoClient(connectionString);
var _database = client.GetDatabase(mongoDatabase);
var collection = _database.GetCollection<BsonDocument>("TestCollection");
var Filter = new BsonDocument("TransactionId", transactionID);
var result = collection.Find(Filter).ToList();
return result.ToString();
}
catch (Exception ex)
{
return ex.ToString();
}
}
static void Main(string[] args)
{
Method1(args).Wait();
Console.ReadLine();
}
static async Task Method1(string[] args)
{
var conString = "mongodb://localhost:27017";
var Client = new MongoClient(conString);
var DB = Client.GetDatabase("local");
var collection = DB.GetCollection<BsonDocument>("TeraData");
var Filter = new BsonDocument("TransactionId", "123");
var list = collection.Find(Filter).ToListAsync();
foreach (var dc in await list)
{
// Console.WriteLine(dc);
}
}
----------------------
Without async/await
public string GetSessionData(string transactionID)
{
try
{
connectionString = ConfigurationManager.AppSettings[mongoConnKey];
mongoDatabase = ConfigurationManager.AppSettings[mongodb];
var client = new MongoClient(connectionString);
var _database = client.GetDatabase(mongoDatabase);
var collection = _database.GetCollection<BsonDocument>("TestCollection");
var Filter = new BsonDocument("TransactionId", transactionID);
var result = collection.Find(Filter).ToList();
return result.ToString();
}
catch (Exception ex)
{
return ex.ToString();
}
}
------------------------
No comments:
Post a Comment