首页 > 解决方案 > pipe.all 不适用于过滤器中的“(”等特殊字符

问题描述

我正在尝试使用 查询 Golang 中的 MongoDB 数据库c.Pipe,但是尽管我在数据库中有诸如此类的项目,但响应始终为空("name": "test case ( parenthesis )")

pipe := c.Pipe([]bson.M{{"$match": bson.M{"name":"("}}})

resp := []bson.M{}

err := pipe.All(&resp)

if err != nil {
  //handle error
}

fmt.Println(resp) // Empty resp

标签: mongodbgo

解决方案


您应该需要一个正则表达式来查询包含character的名称(。正则表达式应该是.*\(.*.


推荐阅读