Error I Cant Figure Out

Hi everyone, I new here so I’m not sure this is the right place to ask this question, so here goes.

I am trying to update a project I have from mgo to mongodb go driver.

I am currently getting this error

multiple-value collection.Distinct() in single-value context

from this code:

func GetDistAlbumMeta1() []string{
	filter := bson.D{{}}
	opts := options.Distinct().SetMaxTime(2 * time.Second)
	client, ctx, cancel, err := Connect("mongodb://db:27017/ampgo")
	CheckError(err, "MongoDB connection has failed")
	collection := client.Database("tempdb1").Collection("meta1")

	DAlbum := []string
	cur, err := collection.Distinct(context.Background(), "album", filter, opts).Decode(&DAlbum)
	CheckError(err, "MongoDB distinct album has failed")
	for i, f := range cur {
		fmt.Println(f)
	}
	return DAlbum
}

I have search google for answers, but this one has me perplexed.

Thank in advance for any assistance.

Charlie

After reading every doc I could get my hands on this fixed the above mentioned code.
The error no long appears and the code runs.

DAlbum := []interface{}
cur, err := collection.Distinct(context.Background(), “album”, filter, opts)

Hope this helps someone else :slight_smile:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.