[CSHARP-1514] Can you pass any mongo query as string to C# driver and get result back? Created: 16/Dec/15 Updated: 05/Apr/19 Resolved: 22/Dec/16 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | API |
| Affects Version/s: | 1.10.1 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Nikhil Salunkhe | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows, Mongo: , , |
||
| Attachments: |
|
| 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: } Same command is C# driver as follow: 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; --------------------------------------- |
| Comments |
| Comment by Craig Wilson [ 16/Dec/15 ] |
|
Couple of things: 1. You'll be restricted to using mongodb 3.2 or greater. The find command was introduced in mongodb 3.2. |
| Comment by Nikhil Salunkhe [ 16/Dec/15 ] |
|
Thanks, Craig. In future, I will post question on the google group that you mentioned. I Reason for running find command manually: We have data management at Xenomorph software Inc to manage financial data. So far using runCommand we have managed to run simple query such as Please see attached screenshot for what are trying to do and may be you Regards, On Wed, Dec 16, 2015 at 2:42 PM, Craig Wilson (JIRA) <jira@mongodb.org> |
| Comment by Craig Wilson [ 16/Dec/15 ] |
|
My apologies, you are using version 1.10 of the driver and not 2.2. You cannot do what you are asking with a string, although it is simple enough to parse by using BsonDocument.Parse(json). You can then pass that anywhere you'd like. Craig |
| Comment by Craig Wilson [ 16/Dec/15 ] |
|
Hi Nihkil, The proper place to ask questions like this is in the user group. We generally reserve jira tickets for features and bug requests. As has been answered in two previous tickets, ").ToList() will do what you want it do to. If you haven't read the documenation, you can find it here. Craig |