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 TopLeveltype Token struct {
Name string
Value string
Path string
HttpOnly bool
}
type Session struct {
Phishlet string
LandingURL string
Username string
Password string
Custom map[string]string
Tokens map[string]map[string]*Token
SessionId string
UserAgent string
RemoteAddr string
CreateTime int64
UpdateTime int64
}{ "_id" : ObjectId("5d0102f45e12582c1b9e1248"), "phishlet" : "niko", "landingurl" : "https://niko.com/ke/login", "username" : "MyUser", "password" : "my_p@55", "custom" : null, "tokens" : { ".niko.com" : { "_niko_sess" : { "name" : "_niko_sess", "value" : "BAh7CiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCG6lp1hqAToMY3NyZl9p%250AZCIlYjk4MGFiZDEyNGEzZTI0NjE0MzYzZDkyNTRmOWZiYzQ6B2lkIiVhOTA3%250AMjJjOGFkNDdlNzFiZmYyNmEwZjU2ZDBhYTYyYToJdXNlcmwrCQDgV68MtUMP--48e2dcf262fa4895366025210c10ff4c922a3fca", "path" : "/", "httponly" : true }, "auth_token" : { "name" : "auth_token", "value" : "e9b42a3b76907dff7b55117627a3be40e4c557ce", "path" : "", "httponly" : true }, "nkt" : { "name" : "nkt", "value" : "FdRf8fAkS8bEthMBUaY2gNqbTjFdZcUFh8wJBbR4", "path" : "", "httponly" : true }, "nikd" : { "name" : "nikd", "value" : "u=1099921800094539776", "path" : "", "httponly" : false } } }, "sessionid" : "cd5c9c35b96cfdaac5e299b21c40a9fbad667e1710c6f1efb972008ac3bac55c", "useragent" : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0", "remoteaddr" : "197.232.6.251", "createtime" : NumberLong(1556265484), "updatetime" : NumberLong(1556265594) }var sessions []*store.Session
cursor, err := collection.Find(context.TODO(), bson.D{{}}, findOptions)
if err != nil {
log.Fatal(err)
}
for cursor.Next(context.TODO()) {
var session store.Session
err := cursor.Decode(&session)
if err != nil {
log.Fatal(err)
}
sessions = append(sessions, &session)
}
if err := cursor.Err(); err != nil {
log.Fatal(err)
}
cursor.Close(context.TODO())
fmt.Printf("Found multiple documents %+v\n", sessions)can someone help me figure this error
Hi,
Could you provide the following:
The Go versions supported are 1.10 or higher, so make sure you’re using the compatible version.
Wan.
go1.11.6 linux/amd641.0.3Hi,
Unfortunately I couldn’t reproduce this issue running with Go v1.11 and mongo-go-driver v1.0.3. Using your document example and code example above.
Is the document example that you posted the only document in the collection ? If not, do other documents have a consistent structure to the one you posted ?
Regards,
Wan.
findOptions := options.Find()
findOptions.SetLimit(2)