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

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

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 1.10.1
    • API

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            nikhilsalunkhe@gmail.com Nikhil Salunkhe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: