mongodb sort

时间:2021-05-25 18:10:59   收藏:0   阅读:0

往常使用options.Find().SetSort(bson.D{{"a", -1},{"b", -1}})结果报错,感觉使用方法没问题,排查之后发现是import的包错了导致。

cannot transform type bson.D to a BSON Document: WriteArray can only write a Array while positioned on a Element or Value but is positioned on a TopLevel

"gopkg.in/mgo.v2/bson"换成"go.mongodb.org/mongo-driver/bson"就没问题了。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!