The complete method should be generic like
public string strGetMaxValue(string strDBName, string strCollectionName, string strKey)
{
// in this method if pass some prms it should give max value
}
The one i tried is
string strMaxValue = "";
MongoServer objServer = this.ConnectToServer();
if ((strDBName != null || strDBName != "") && (strCollectionName != null || strCollectionName != ""))
{
string[] strArrays = new string[1];
strArrays[0] = strKey;
//MongoCursor<BsonDocument> objCursor = objServer.GetDatabase(strDBName).GetCollection(strCollectionName).Find(query).SetSortOrder(SortBy.Descending(strArrays)).SetLimit(1);
var objCursor = objServer.GetDatabase(strDBName).GetCollection(strCollectionName).FindAll().SetSortOrder(SortBy.Descending(strArrays)).SetLimit(1).ToArray();
}
In that objCursor i m getting that document which i need. i want to extract that field value and needs to send it as return parameter.
The method should be generic as such the key value may a field in nested document also.
how to achieve this.?