Details
-
Bug
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
-
None
-
windows/amd64, go1.12.5
Description
I've tried to fetch a collection with the Find method. After putting an empty document as filter, .Find() returns a cursor which is empty. Also no error occures somewhere.
I followed the example from the README.md in the github repository.
Tried following:
- Lookup database with MongoDB Compass, `test.user` wasn't empty
- .Insert works
- .FindOne returns a document
- Tried Mongo CLI, returns all documents
- Tried pymongo, also returns all documents
I made a minimal test code:
package main |
|
|
import ( |
"go.mongodb.org/mongo-driver/bson" |
"go.mongodb.org/mongo-driver/mongo" |
"go.mongodb.org/mongo-driver/mongo/options" |
"log" |
)
|
|
|
// fatalErr is a helper method for errors
|
func fatalErr(err error) {
|
if err != nil { |
log.Fatal(err)
|
}
|
}
|
|
|
// Connects to the database and returns a client or calls log.Fatal on error
|
func connectDb() *mongo.Client {
|
opt := options.Client().ApplyURI("mongodb://localhost:27017") |
client, err := mongo.NewClient(opt)
|
fatalErr(err)
|
|
|
fatalErr(client.Connect(nil))
|
return client |
}
|
|
|
func main() {
|
db := connectDb()
|
coll := db.Database("test").Collection("user") |
|
|
// When I use coll.FindOne(nil, bson.D{}) instead, it finds a document. |
|
|
// test.user contains multiple records. Find still returns nothing. |
cur, err := coll.Find(nil, bson.D{})
|
fatalErr(err)
|
defer fatalErr(cur.Close(nil))
|
|
|
for cur.Next(nil) { |
// Never called |
log.Println("->", cur.ID()) |
}
|
|
|
fatalErr(cur.Err())
|
log.Println("Done.") |
}
|
|
Can someone reproduce this bug? Or has anyone tipps where I can lookup for mistakes I possible made?
Greetings, Matthias Schild