Currently working on a Golang project but in some controllers i get
package controller
import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"gopkg.in/mgo.v2/bson"
)
var updatedObj primitive.D
updatedObj = append(updatedObj, bson.E{"table", order.Table_id})
I always get (bson.E) E is not declared by package bson
3
Answers
According to https://stackoverflow.com/users/13415116/phonaputer
I actually imported the wrong package for bson
This solved the error and it became correct
I think it is because bson doesn’t have any
E
included in their package (because it is reading the other package:gopkg.in/mgo.v2/bson
).You can try something like this:
It looks like you are importing the wrong
bson
package.As you can see here,
gopkg.in/mgo.v2/bson
does not include the "E" type.Based on the other packages you are using, I think perhaps you want this one:
go.mongodb.org/mongo-driver/bson
? Theprimitive
package you are using is a subpackage of this package so I think the two should work together correctly.