For unit testing purposes, I\'d like to test my class mappings without reading and writing documents into the MongoDB database. To handle special cases such as circular parent
Use yield
keyword to return data as you want.
public IEnumerable GetMongoFields(string collectionName)
{
var connectionString = ConfigurationManager.ConnectionStrings[DbConfig.GetMongoDb()].ConnectionString;
var databaseName = MongoUrl.Create(connectionString).DatabaseName;
MongoClient client = new MongoClient(connectionString);
var server = client.GetServer();
var db = server.GetDatabase(databaseName);
var collection = db.GetCollection(collectionName);
var list = collection.FindAll().ToList();
yield return list.ToJson();
}