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 :(
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}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.