title: Using golang and mgo, how do I search for a range of values in MongoDB?
body: <p>I worked through the example on the <a href="http://labix.org/mgo" rel="noreferrer">mgo homepage</a>, but I'm struggling to find a way to query a range of values.  The line:<br>
  <code>searchResults, searchErr = SearchReading(bson.M{"k": key, "t": { $gte: start, $lte: end } }, limit)</code><br>
  fails with:<br>
  <code>line67: syntax error: unexpected $</code><br>
  <code>line67: missing type in composite literal</code></p>
  
  <p>I left out the non-essential bits of code...</p>
  
  <pre><code>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(&amp;searchResults)
          if limit &lt; 0 {
              fn = c.Find(q).All(&amp;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
  }
  </code></pre>