前言 1.limit()方法 db.collection.find().limit(NUMBER) > db.lesson.insertMany([{"name":"lua", "price":"$20.00"}, {"name":"Go", "price":"$30.00"}, {"name":"python", "price":"$40.00"}]) { "acknowledged" : true, "insertedIds" : [ ObjectId("5c78d839b881b2c3b7328602"), ObjectId("5c78d839b881b2c3b7328603"), ObjectId("5c78d839b881b2c3b7328604") ] } > db.lesson.find().limit(2) { "_id" : ObjectId("5c78d839b881b2c3b7328602"), "name" : "lua", "price" : "$20.00" } { "_id" : ObjectId("5c78d839b881b2c3b7328603"), "name" : "Go", "price" : "$30.00" } 2.skip()方法 db.collection.find().skip(NUMBER) > db.lesson.find().skip(1) { "_id" : ObjectId("5c78d839b881b2c3b7328603"), "name" : "Go", "price" : "$30.00" } { "_id" : ObjectId("5c78d839b881b2c3b7328604"), "name" : "python", "price" : "$40.00" } > db.lesson.find().skip(1).limit(1) { "_id" : ObjectId("5c78d839b881b2c3b7328603"), "name" : "Go", "price" : "$30.00" } > db.lesson.find().limit(1).skip(1) { "_id" : ObjectId("5c78d839b881b2c3b7328603"), "name" : "Go", "price" : "$30.00" } 总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对自学php网的支持。
查看更多关于MongoDB中方法limit和skip的使用的详细内容...