组合文字go中缺少类型,而map文字go中缺少键 [英] missing type in composite literal go AND missing key in map literal go

查看:47
本文介绍了组合文字go中缺少类型,而map文字go中缺少键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MongoDB进行分页

Im trying to do Pagination with 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中缺少类型,而地图文字go中缺少键

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

它抱怨这部分:

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

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

由于这个错误持续了很多小时,而且让我非常沮丧,所以我一直停留在它上面.

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

请帮助:(

推荐答案

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}

并且:

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

这篇关于组合文字go中缺少类型,而map文字go中缺少键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆