mongodb sort

往常使用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"就没问题了。

原文地址:https://www.cnblogs.com/mentalidade/p/14807535.html