diff --git a/src/go/mongolib/explain/explain_test.go b/src/go/mongolib/explain/explain_test.go index 13e6fb78..c2826ab2 100644 --- a/src/go/mongolib/explain/explain_test.go +++ b/src/go/mongolib/explain/explain_test.go @@ -84,6 +84,8 @@ func TestExplain(t *testing.T) { "insert": "Cannot explain cmd: insert", "mapreduce": "Cannot explain cmd: mapReduce", "update": "", + "explain": "Cannot explain cmd: explain", + "eval": "Cannot explain cmd: eval", } expectError := map[string]string{} diff --git a/src/go/mongolib/fingerprinter/fingerprinter.go b/src/go/mongolib/fingerprinter/fingerprinter.go index 621a091b..7369e5fc 100644 --- a/src/go/mongolib/fingerprinter/fingerprinter.go +++ b/src/go/mongolib/fingerprinter/fingerprinter.go @@ -81,20 +81,31 @@ func (f *Fingerprint) Fingerprint(doc proto.SystemProfile) (string, error) { switch doc.Op { case "remove", "update": op = doc.Op - ns := strings.Split(doc.Ns, ".") + ns := strings.SplitN(doc.Ns, ".", 2) if len(ns) == 2 { collection = ns[1] } case "insert": op = doc.Op - ns := strings.Split(doc.Ns, ".") + ns := strings.SplitN(doc.Ns, ".", 2) if len(ns) == 2 { collection = ns[1] } retKeys = []string{} case "query": + // EXPLAIN MongoDB 2.6: + // "query" : { + // "query" : { + // + // }, + // "$explain" : true + // }, + if _, ok := doc.Query.Map()["$explain"]; ok { + op = "explain" + break + } op = "find" - ns := strings.Split(doc.Ns, ".") + ns := strings.SplitN(doc.Ns, ".", 2) if len(ns) == 2 { collection = ns[1] } @@ -140,6 +151,12 @@ func (f *Fingerprint) Fingerprint(doc proto.SystemProfile) (string, error) { } case "geoNear": retKeys = []string{} + case "explain": + retKeys = []string{} + case "$eval": + op = "eval" + collection = "" + retKeys = []string{} } } diff --git a/src/go/mongolib/fingerprinter/fingerprinter_test.go b/src/go/mongolib/fingerprinter/fingerprinter_test.go index cbdb1d96..8225452d 100644 --- a/src/go/mongolib/fingerprinter/fingerprinter_test.go +++ b/src/go/mongolib/fingerprinter/fingerprinter_test.go @@ -113,6 +113,16 @@ func TestFingerprints(t *testing.T) { "distinct_3.2.16": "DISTINCT coll a,b", "distinct_3.4.7": "DISTINCT coll a,b", "distinct_3.5.11": "DISTINCT coll a,b", + "explain_2.6.12": "EXPLAIN", + "explain_3.0.15": "EXPLAIN", + "explain_3.2.16": "EXPLAIN", + "explain_3.4.7": "EXPLAIN", + "explain_3.5.11": "EXPLAIN", + "eval_2.6.12": "EVAL", + "eval_3.0.15": "EVAL", + "eval_3.2.16": "EVAL", + "eval_3.4.7": "EVAL", + "eval_3.5.11": "EVAL", "find_empty_2.6.12": "FIND coll", "find_empty_3.0.15": "FIND coll", "find_empty_3.2.16": "FIND coll", diff --git a/src/go/mongolib/proto/system.profile.go b/src/go/mongolib/proto/system.profile.go index 41d00f90..295c3a55 100644 --- a/src/go/mongolib/proto/system.profile.go +++ b/src/go/mongolib/proto/system.profile.go @@ -120,6 +120,22 @@ func (self ExampleQuery) ExplainCmd() bson.D { if cmd.Len() == 0 { cmd = self.Query } + + // MongoDB 2.6: + // + // "query" : { + // "query" : { + // + // }, + // "$explain" : true + // }, + if _, ok := cmd.Map()["$explain"]; ok { + cmd = BsonD{ + {"explain", ""}, + } + break + } + if cmd.Len() == 0 || cmd[0].Name != "find" { var filter interface{} if cmd.Len() > 0 && cmd[0].Name == "query" { diff --git a/src/go/tests/doc/script/profile/eval.js b/src/go/tests/doc/script/profile/eval.js new file mode 100644 index 00000000..fb3c07d9 --- /dev/null +++ b/src/go/tests/doc/script/profile/eval.js @@ -0,0 +1 @@ +db.eval("db") diff --git a/src/go/tests/doc/script/profile/explain.js b/src/go/tests/doc/script/profile/explain.js new file mode 100644 index 00000000..fcf81bce --- /dev/null +++ b/src/go/tests/doc/script/profile/explain.js @@ -0,0 +1,3 @@ +var coll = db.coll + +coll.find().explain()