Details
Description
Good day! Sorry for my bad English.
I have a problem. My program must recive out command in style shell MongoDB and execute, but i not understand how make it.
I find old example http://stackoverflow.com/questions/6120629/can-i-do-a-text-query-with-the-mongodb-c-sharp-driver, but he not compiled with current version driver. I modify example, but he looping in point return cursor.ToList();. Database have 33 document, in console all works. How can i resolve my problem?
Modify code:
MongoServerSettings mss = new MongoServerSettings();
|
mss.ConnectionMode = ConnectionMode.Automatic;
|
mss.Server = new MongoServerAddress("localhost", 27020);
|
MongoServer ms = new MongoServer(mss);
|
var collection = ms.GetDatabase("local").GetCollection("title");
|
var items = collection.GetItems<BsonDocument>("{ val : 'А'}", "{val:1}");
|
|
|
public static class MongoDbExt
|
{
|
public static List<T> GetItems<T>(this MongoCollection collection,
|
string queryString, string orderString) where T : class
|
{
|
MongoCursor<T> cursor;
|
SortByWrapper order = null;
|
QueryDocument query = null;
|
if ((queryString != "") && (queryString != null))
|
{
|
var queryDoc = BsonSerializer.Deserialize<BsonDocument>(queryString);
|
query = new QueryDocument(queryDoc);
|
}
|
cursor = collection.FindAs<T>(query);
|
//cursor = collection.FindAs<T>(null);
|
if ((orderString != "") && (orderString != null))
|
{
|
var orderDoc = BsonSerializer.Deserialize<BsonDocument>(orderString);
|
order = new SortByWrapper(orderDoc);
|
}
|
cursor.SetSortOrder(order);
|
return cursor.ToList();
|
}
|
}
|