我在mgo主页上浏览了该示例,但是我一直在努力寻找一种查询一系列值的方法。该行:searchResults, searchErr = SearchReading(bson.M{"k": key, "t": { $gte: start, $lte: end } }, limit)失败并显示:line67: syntax error: unexpected $line67: missing type in composite literal我省去了不必要的代码...type Reading struct { K string "k" T int64 "t" V float64 "v"}func SearchReading(q interface{}, limit int) (searchResults []Reading, searchErr string) { searchErr = "" searchResults = []Reading{} query := func(c *mgo.Collection) error { fn := c.Find(q).Limit(limit).All(&searchResults) if limit < 0 { fn = c.Find(q).All(&searchResults) } return fn } search := func() error { return withCollection("reading", query) } err := search() if err != nil { searchErr = "Database Error" } return}func GetReadingsForKey(key string, start int64, end int64, limit int) (searchResults []Reading, searchErr string) { searchResults, searchErr = SearchReading(bson.M{"k": key, "t": { $gte: start, $lte: end } }, limit) return}
1 回答
三国纷争
TA贡献1804条经验 获得超7个赞
该行:
searchResults, searchErr = SearchReading(bson.M{"k": key, "t": { $gte: start, $lte: end } }, limit)
需要更改为:
searchResults, searchErr = SearchReading(bson.M{"k": key, "t": bson.M{"$gte": start, "$lte": end}}, limit)
- 1 回答
- 0 关注
- 197 浏览
添加回答
举报
0/150
提交
取消