Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1680

How use driver with command like shell?

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: 2.2.3
    • Component/s: API
    • Environment:
      Windows 10, FW 4.5, MS VS 2015 Update 2
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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();
              }
          }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            kamakama Andrzej Kaminsky
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: