Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:26:40+00:00 2026-06-13T18:26:40+00:00

I worked through the example on the mgo homepage , but I’m struggling to

  • 0

I worked through the example on the mgo homepage, but I’m struggling to find a way to query a range of values. The line:
searchResults, searchErr = SearchReading(bson.M{"k": key, "t": { $gte: start, $lte: end } }, limit)
fails with:
line67: syntax error: unexpected $
line67: missing type in composite literal

I left out the non-essential bits of 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(&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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:26:41+00:00Added an answer on June 13, 2026 at 6:26 pm

    The line:

    searchResults, searchErr = SearchReading(bson.M{"k": key, "t": { $gte: start, $lte: end } }, limit)
    

    needs to change to:

    searchResults, searchErr = SearchReading(bson.M{"k": key, "t": bson.M{"$gte": start, "$lte": end}}, limit)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've worked myself through the rapidXML sources and managed to read some values. Now
I'm new to Workflow Foundation. I've worked my way through one book (K. Scott
I've just worked through the Rail example supplied by Apple: http://developer.apple.com/Tools/developonrailsleopard.html Now that I'm
I've tried every example I can find on the web but I cannot get
I had some code that ran commands through Runtime.getRuntime.exec(String) , and it worked on
I want to iterate through all 5 character combinations of 0-9, a-z. I worked
I have an Java applet that loads native code through JNI. Everything worked just
I though I had a good understanding of how C++ worked but I'm confused
I am looking through some example Fibonacci sequence clojure code: (def fibs (lazy-cat [1
Ok, so I've worked through a number of bugs in the following short script.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.