drop $db; fix group

This commit is contained in:
Kamil Dziedzic
2017-08-31 22:12:01 +02:00
parent 31eb04fc88
commit 7d4be1b348

View File

@@ -138,6 +138,18 @@ func (self ExampleQuery) ExplainCmd() bson.D {
{"find", coll}, {"find", coll},
{"filter", filter}, {"filter", filter},
} }
} else {
for i := range cmd {
// drop $db param as it is not supported in MongoDB 3.0
if cmd[i].Name == "$db" {
if len(cmd) - 1 == i {
cmd = cmd[:i]
} else {
cmd = append(cmd[:i], cmd[i+1:]...)
}
break
}
}
} }
case "update": case "update":
s := strings.SplitN(self.Ns, ".", 2) s := strings.SplitN(self.Ns, ".", 2)
@@ -192,8 +204,8 @@ func (self ExampleQuery) ExplainCmd() bson.D {
break break
} }
if v, ok := cmd[0].Value.(BsonD); ok { if group, ok := cmd[0].Value.(BsonD); ok {
for i := range v { for i := range group {
// for MongoDB <= 3.2 // for MongoDB <= 3.2
// "$reduce" : function () {} // "$reduce" : function () {}
// It is then Unmarshaled as empty value, so in essence not working // It is then Unmarshaled as empty value, so in essence not working
@@ -206,9 +218,9 @@ func (self ExampleQuery) ExplainCmd() bson.D {
// //
// The $reduce function shouldn't affect explain execution plan (e.g. what indexes are picked) // The $reduce function shouldn't affect explain execution plan (e.g. what indexes are picked)
// so we ignore it for now until we find better way to handle this issue // so we ignore it for now until we find better way to handle this issue
if v[i].Name == "$reduce" { if group[i].Name == "$reduce" {
v[i].Value = "" group[i].Value = "{}"
cmd[0].Value = v cmd[0].Value = group
break break
} }
} }