简体   繁体   中英

MongoDB Native Node Driver: Explain is Broken?

I can't get a proper explain using the native mongodb driver for Node.js. When I use the mongo shell, everything is fine. Is my syntax wrong? Anything else I could be doing wrong?

db.user.find({},{explain:true}).toArray

db.user.find({}).explain

I've tried both of these, there are two documents in the user table, and it gives me this output:

{ cursor: 'BasicCursor',
  isMultiKey: false,
  n: 1,
  nscannedObjects: 1,
  nscanned: 1,
  nscannedObjectsAllPlans: 1,
  nscannedAllPlans: 1,
  scanAndOrder: false,
  indexOnly: false,
  nYields: 0,
  nChunkSkips: 0,
  millis: 0,
  allPlans: 
   [ { cursor: 'BasicCursor',
       isMultiKey: false,
       n: 1,
       nscannedObjects: 1,
       nscanned: 1,
       scanAndOrder: false,
       indexOnly: false,
       nChunkSkips: 0 } ],
  server: 'Rocket.local:27017',
  filterSet: false,
  stats: 
   { type: 'LIMIT',
     works: 2,
     yields: 0,
     unyields: 0,
     invalidates: 0,
     advanced: 1,
     needTime: 1,
     needFetch: 0,
     isEOF: 1,
     children: [ [Object] ] } }

This is wrong. When I run this same query in the mongo shell, it gives the the correct output:

"cursor" : "BasicCursor",
    "isMultiKey" : false,
    "n" : 2,
    "nscannedObjects" : 2,
    "nscanned" : 2,
    "nscannedObjectsAllPlans" : 2,
    "nscannedAllPlans" : 2,
    "scanAndOrder" : false,
    "indexOnly" : false,
    "nYields" : 0,
    "nChunkSkips" : 0,
    "millis" : 0,
    "server" : "Rocket.local:27017",
    "filterSet" : false,
    "stats" : {
        "type" : "COLLSCAN",
        "works" : 4,
        "yields" : 0,
        "unyields" : 0,
        "invalidates" : 0,
        "advanced" : 2,
        "needTime" : 1,
        "needFetch" : 0,
        "isEOF" : 1,
        "docsTested" : 2,
        "children" : []
    }

I've been having a few other (related problems) as well...

Limit = 1 = 1ms, Limit > 1 = 150ms (mongo-melt-down)

Odd MongoDB/Node Explain Results

我做了很多底层分析和优化之后,应该在驱动程序的2.0.13中修复。

Looks like a 2.0.x issue. Already submitted ticket.

Seems to be a problem with the 2.0.x driver: here's a thread...

I just ran the exact same query with 2.0.x and 1.4.x. When Limit = 1, both perform fast ~1ms. When Limit = 2, the 1.4.x version stays around 1ms but the 2.0.x version jumps to 25ms. So, it's not just an issue with the explain output - that's just a symptom of the problem.

On Thursday, January 8, 2015 9:04:05 AM UTC-8, Joshua Abrams wrote: Interesting... exact same query using 1.4.x yields a proper explain where n = 2 (and so on). Could this be affecting performance? When I run a query where Limit = 1 it's fast (as expected) but when Limit = 2 it's 100x slower...

On Thursday, January 8, 2015 8:52:28 AM UTC-8, christkv wrote: not really. My suggestion is to make a minimal reproducible test case (code and data) and open a ticket on jira.mongodb.com. kind of hard to know what could be happening. it's unlikely to be the driver but one never knows. try with the 1.4.x branch aswell just to at least rule out that it's a 2.0.x branch issue.

On Thursday, January 8, 2015 5:47:45 PM UTC+1, Joshua Abrams wrote: Just checked and I'm using 2.0.12 of the driver. Any other thoughts?

On Thursday, January 8, 2015 8:23:16 AM UTC-8, christkv wrote: explain is just retuning all the results in the driver instead of partial results. thus you get the plan. One thing that comes to mind might be that you are on a driver earlier than 1.4.19 that had an error where batchSize was set to 1.

On Thursday, January 8, 2015 5:01:42 PM UTC+1, Joshua Abrams wrote: I've been having a suite of performance issues lately with the driver. Limit = 1 = 1ms, Limit > 1 = 150ms (mongo-melt-down)

Not sure what the root cause it - and it's impossible to debug when I can't get a proper explain: MongoDB Native Node Driver: Explain is Broken?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM