duanmu0834 2019-04-20 21:10
浏览 592
已采纳

Mongodb-go-driver接口转换:interface {}是原始的.ObjectID,而不是原始的.ObjectID(来自不同包的类型)

I can display the result.InsertedID with no problem, however, I keep getting the above error when I attempt to access the value to use it other places. I want to get the value before I leave the method that inserts the new object. The error message does not make any sense.

I get this error with res.InsertedID.(primitive.ObjectID). What is the proper way?

How do I get the concrete value preferably as a hex string? Even if I can get the value as a concrete ObjectID and not an interface I would be happy.

  • 写回答

1条回答 默认 最新

  • douli7841 2019-04-21 02:18
    关注

    There are two packages in the application with name primitive containing a type named ObjectID. The concrete value in the type assertion is from one of those packages. The asserted type is from the other package. The type assertion panics because the types are not equal.

    Fix by modifying the application to use a single import path for the primitive package (and the entire driver).

    The canonical import path of the package was changed from github.com/mongodb/mongo-go-driver/bson/primitive to go.mongodb.org/mongo-driver/bson/primitive in February 2019. It is likely that the application uses both of these import paths.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题