First I run a MongoDB 2.6 with docker:
docker run -p 27018:27017 --name mongo26 -d mongo:2.6
Then I using mongo-go-driver to try List `Limit` Option, the code is following:
package main import ( "context" "go.mongodb.org/mongo-driver/bson" "github.com/bxcodec/faker" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) type Model struct { A int64 `bson:"a,omitempty"` } func main() { opts := options.Client().ApplyURI("mongodb://127.0.0.1:27018") client, err := mongo.NewClient(opts) if err != nil { panic(err) } if err := client.Connect(context.Background()); err != nil { panic(err) } genData(client) listData(client) } func genData(cli *mongo.Client) { var coll = cli.Database("test").Collection("test") for i := 0; i < 1001; i++ { m := Model{A: faker.RandomUnixTime()} if _, err := coll.InsertOne(context.Background(), m); err != nil { panic(err) } } } func listData(cli *mongo.Client) { var coll = cli.Database("test").Collection("test") var data = []Model{} var opts = options.Find().SetSkip(0).SetLimit(1000) if cursor, err := coll.Find(context.Background(), bson.M{}, opts); err != nil { panic(err) } else { if err = cursor.All(context.Background(), &data); err != nil { panic(err) } } println(len(data)) }
Result is 1001,Which we expected to be 1000.
- is related to
-
GODRIVER-1728 Send lower batchSize on getMore commands to unskip batchSize key in command monitoring tests
- Closed