我正在尝试使用MongoDB 进行分页
我写这个代码:
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)
现在它一直在抱怨:
复合文字go中缺少类型AND映射文字go 中缺少键
它抱怨这个部分:
findOptions.SetSort(bson.M{{"_id", 1}})
和
bson.M{{"_id", bson.M{{"$gte", last_id}}}}, findOptions)
我已经被这个错误困扰了好几个小时了,非常令人沮丧。
请帮助:(
bson.M
是一个映射:
type M map[string]interface{}
因此,使用map复合文本语法来创建它的值:
bson.M{"_id": 1}
和:
bson.M{"_id": bson.M{"$gte": last_id}}