Monday, 23 April 2018

Retrieving /getting data from Mongo collection using C#


 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");          List<BsonDocument> result1 = _collection.AsQueryable<BsonDocument>().ToList();    

                return result1.ToString();      
}
catch (Exception ex)
            {
                return ex.ToString();
            }
}

No comments:

Post a Comment