问题
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 :(
回答1:
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}}
来源:https://stackoverflow.com/questions/64226091/missing-type-in-composite-literal-go-and-missing-key-in-map-literal-go