mongodb 查询有关limit选项问题;

k8svip · · 1782 次点击
更多评论
一次查询多条数据(查询createtime>=3,限制取2条,createtime从大到小排序的数据) ```go if cursor, err = collection.Find(getContext(), bson.M{"createtime": bson.M{"$gte": 2}}, options.Find().SetLimit(2), options.Find().SetSort(bson.M{"createtime": -1})); err != nil { checkErr(err) } if err = cursor.Err(); err != nil { checkErr(err) } defer cursor.Close(context.Background()) for cursor.Next(context.Background()) { if err = cursor.Decode(&howie); err != nil { checkErr(err) } howieArrayEmpty = append(howieArrayEmpty, howie) } fmt.Printf("Find查询到的数据:%v\n", howieArrayEmpty) ``` > 参考[码农教程](http://www.manongjc.com/article/22514.html)
#1