Caitlin Walsh
Caitlin Walsh

Reputation: 37

missing type in composite literal go AND missing key in map literal go

Im trying to do Pagination with MongoDB

I write this code:

findOptions := options.Find()
    findOptions.SetLimit(20)
    findOptions.SetSort(bson.M{{"_id", 1}})

    cursor, err34 := collection.Find(context.Background(), bson.M{{"_id", bson.M{{"$gte", last_id}}}}, findOptions)

Now It keeps complaining:

missing type in composite literal go AND missing key in map literal go

It complains for this part:

findOptions.SetSort(bson.M{{"_id", 1}})

and

bson.M{{"_id", bson.M{{"$gte", last_id}}}}, findOptions)

I'm stuck with this error since so many hours and its very frustrating.

Please Help :(

Upvotes: 1

Views: 1961

Answers (1)

icza
icza

Reputation: 417672

bson.M is a map:

type M map[string]interface{}

So use the map composite literal syntax to create a value of it:

bson.M{"_id": 1}

And:

bson.M{"_id": bson.M{"$gte": last_id}}

Upvotes: 5

Related Questions