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.

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

报告相同问题?

悬赏问题

  • ¥100 高价邀请复制 域天d8联网狗
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?