HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
If you need to read a specified number of data records in MongoDB, you can use the Limit MongoDB method, limit () method accepts a numeric parameter that specifies the number of records read from MongoDB in.
limit () method basic syntax is as follows:
>db.COLLECTION_NAME.find().limit(NUMBER)
Col data collection are as follows:
{ "_id" : ObjectId("56066542ade2f21f36b0313a"), "title" : "PHP 教程", "description" : "PHP 是一种创建动态交互性站点的强有力的服务器端脚本语言。", "by" : "本教程", "url" : "https://w3resource.net/", "tags" : [ "php" ], "likes" : 200 } { "_id" : ObjectId("56066549ade2f21f36b0313b"), "title" : "Java 教程", "description" : "Java 是由Sun Microsystems公司于1995年5月推出的高级程序设计语言。", "by" : "本教程", "url" : "https://w3resource.net/", "tags" : [ "java" ], "likes" : 150 } { "_id" : ObjectId("5606654fade2f21f36b0313c"), "title" : "MongoDB 教程", "description" : "MongoDB 是一个 Nosql 数据库", "by" : "本教程", "url" : "https://w3resource.net/", "tags" : [ "mongodb" ], "likes" : 100 }
Examples of the above query to display the document in two records:
> db.col.find({},{"title":1,_id:0}).limit(2) { "title" : "PHP 教程" } { "title" : "Java 教程" } >
NOTE: If you do not specify the limit () method parameters are displayed in the collection of all data.
In addition we can use the limit () method to read a specified number of data, you can also use the skip () method to skip a specified number of data, skip method also accepts a numeric parameter as the number of records to skip.
skip () method script syntax is as follows:
>db.COLLECTION_NAME.find().limit(NUMBER).skip(NUMBER)
The above examples show only the second document data
>db.col.find({},{"title":1,_id:0}).limit(1).skip(1) { "title" : "Java 教程" } >
NOTE: skip () method of the default parameter is 0.