Can you pass any mongo query as string to C# driver and get result back?

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.10.1
    • Component/s: API
    • Environment:
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I am using Mongo C# driver to query data. Executing command from shell/robomongo seems easy to use but trying to execute same command from C# seems little difficult.

      e.g. In Shell, I am executing following command:
      db.runCommand(
      {
      "find":"Equity",
      "filter":

      {"Ticker":"AAPL US Equity", "Ask":101.2600000000000100}

      }
      )

      Same command is C# driver as follow:
      var client = new MongoClient();
      var database = client.GetServer().GetDatabase("MONGOXDB");
      Dictionary<string, object> dictionary = new Dictionary<string, object>();
      dictionary.Add("find", "Equity");

      BsonElement bElement1 = new BsonElement("Ticker", "AAPL US Equity");

      BsonElement bElement2 = new BsonElement("Ask"(BsonValue)101.2600000000000100);

      dictionary.Add("filter", new BsonDocument

      { bElement1, bElement2 }

      );

      var command = new CommandDocument

      { dictionary }

      ;

      CommandResult result = database.RunCommand(command);

      BsonDocument bdocument = result.Response;

      ---------------------------------------
      Now question is there way of passing Mongo query as string in C# and then get result back.

            Assignee:
            Unassigned
            Reporter:
            Nikhil Salunkhe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: