[CSHARP-1250] Run the Explain command on a db Find Created: 23/Apr/15 Updated: 05/Apr/19 Resolved: 17/Jun/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 2.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Peter Gordon | Assignee: | Craig Wilson |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Case: | (copied to CRM) | ||||||||
| Description |
|
Using the new C# 2.0 driver, I cannot seem to figure out how to run an Explain query. An example query is:
someCollection is of type IMongoCollection<SomeType>. I am importing the following namespaces:
I am trying to do this without using the legacy driver but cannot figure out how to do it even with the legacy driver without creating a legacy connection since my Database connection returns an IMongoDatabase and none of the find options returns a MongoQuery. |
| Comments |
| Comment by Craig Wilson [ 17/Jun/15 ] | |||||||
|
I've added ticket | |||||||
| Comment by Craig Wilson [ 27/Apr/15 ] | |||||||
|
Hi Peter, I understand. For Find, the answer is actually pretty straightforward. We have a FindOptions parameter you can pass into the Find method that will add the $explain operator correctly. One of the problems with explain is that is changes the result type significantly. As such, if your collection isn't of type BsonDocument, then you'll need to project into a BsonDocument. Unfortunately, there isn't a great way to do this right now. I'll add a ticket to make it easier to do this. Until then, you can use a Project call with an empty BsonDocument.
Craig | |||||||
| Comment by Peter Gordon [ 27/Apr/15 ] | |||||||
|
Hey Craig, I can run the explain in the shell but I have a suite of debugging tools/performance optimization checks that we run in our development environment that allows us to run an explain on all queries run for any given request and save the explain results. We can then go through and query the results to find potential issues with indexing, etc.... to improve performance. The benefit is that the explains are run on the actual queries performed on the app and I do not have to pull the query statements and type them in the shelll which would be a slow process for some of our complex queries. We have looked at using the Mongo profiler to do this as well but we found that limiting the scope of the analysis to the specific queries on the request we are working with for a specific developer saves a lot of time and confusion as the profiler seems to be an "all or nothing" mechanism (unless we set to only track long running queries - but then we are still not limiting scope to the one area currently being worked on by the developer). This is not a huge deal but would be beneficial for us ... even if the Explain doc returned is a dynamic BsonDocument that we can process on our end. I have tried running a Find by passing in a document in the format { $query: ..., $explain: 1 }but that generated an error due to the $ illegal character in the driver. (http://docs.mongodb.org/manual/reference/operator/meta/explain/) Thanks | |||||||
| Comment by Craig Wilson [ 27/Apr/15 ] | |||||||
|
Hi Peter, Explain is/has undergone some changes and adding it to the driver before that is done would have been a mistake. In addition, we feel that most explanations happen in the shell and not in the drivers. As a result, we've not included explain as part of the API. Is there any reason you aren't able to do your explanation from the shell? Craig |