0

I am trying to print the 6 objects I know contain my search term. I am able to see the query array of the right length/size/capacity. But when I iterate the array and print, they do not contain any information.

My initial reaction is that maybe I have the wrong interface for my results.

code snippet:

var sTerm = "Google"
index := mgo.Index{
    Key: []string{"product.maker", "product.product"},
}

err = col.EnsureIndex(index)
//err = col.EnsureIndexKey("product.maker")
check(err)

//query := col.Find(bson.M{"$text": bson.M{"$search": sTerm}})
query := col.Find(bson.M{"product.maker": sTerm})
//query := col.Find(bson.M{"product.maker": &bson.RegEx{Pattern: sTerm, Options: "i"}})
fmt.Println(query)

var res []struct{ Value int }
err = query.All(&res)
check(err)
fmt.Println(res)
for i := 0; i < len(res); i++ {
    fmt.Println(res[i])
}

output:

&{{0 0} 0xc042056d00 {{devbase.devices map[product.maker:Google] 0 0 <nil> 0 <nil> 0 {<nil> <nil> <nil> false false [] 0 0 } false []} 0.25 0}}
[{0} {0} {0} {0} {0} {0}]
{0}
{0}
{0}
{0}
{0}
{0}

For now, I am hardcoding the search term, I have already set up a http handler function for the response and a Gorilla mux.

Cit5
  • 400
  • 5
  • 19

1 Answers1

1

NEVER MIND!

var res = []bson.M{}

I know I know... I will go shoot myself now. haha! Thanks anyways!

tgogos
  • 23,218
  • 20
  • 96
  • 128
Cit5
  • 400
  • 5
  • 19