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.
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.