I want to solve this problem when called find query.
This is running Golang, and use package ""gopkg.in/mgo.v2/bson".
import "gopkg.in/mgo.v2"
import "fmt"
/* mongodb */
info := &mgo.DialInfo{
Addrs: []string{1.1.1.1+ ":" + 27017},
Database: MgName,
Username: MgId,
Password: MgPasswd,
}
mgconn, err := mgo.DialWithInfo(info)
if err != nil {
fmt.Printf("[ERR ] mongodb : %s
", err)
return (-1)
}
/* error check on every access */
mgconn.SetSafe(&mgo.Safe{})
MgConn := mgconn.DB(MgName)
col := MgConn.C("test")
ip := "1.1.1.1"
docs := []interface{}{
bson.M{"message": bson.M{"$regex": bson.RegEx{`name:agent`, ""}}},
bson.M{"message": bson.M{"$regex": bson.RegEx{ip, ""}}},
}
err := col.Find(docs).Sort("-time").One(&statistic)
if err != nil {
fmt.Printf("[INFO] mongodb select : %s
", err)
}
This is the error message:
Failed to parse: filter: [ { message: { $regex: /name:agent/ } }, {
message: { $regex: /192.168.18.61/ } } ]. 'filter' field must be of
BSON type object.