📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
The Limit() Method
Syntax
> db.COLLECTION_NAME.find().limit(NUMBER)
Example
> db.posts.find().pretty();
{
"_id" : ObjectId("5e184a067695f4d696a0598d"),
"title" : "MongoDB Overview",
"description" : "MongoDB is no sql database",
"by" : "Java Guides",
"url" : "https://javaguides.net",
"tags" : [
"mongodb",
"database",
"NoSQL"
],
"likes" : 100
}
{
"_id" : ObjectId("5e184a067695f4d696a0598e"),
"title" : "NoSQL Database",
"description" : "NoSQL database doesn't have tables",
"by" : "Java Guides",
"url" : "https://javaguides.net",
"tags" : [
"mongodb",
"database",
"NoSQL"
],
"likes" : 20,
"comments" : [
{
"user" : "user1",
"message" : "My first comment",
"dateCreated" : ISODate("2013-12-10T09:35:00Z"),
"like" : 0
}
]
}
{
"_id" : ObjectId("5e18544a7695f4d696a0598f"),
"title" : "MongoDB CRUD Operations",
"description" : "MongoDB CRUD Operations",
"by" : "Java Guides",
"url" : "https://javaguides.net",
"tags" : [
"mongodb",
"database",
"NoSQL"
],
"likes" : 20,
"comments" : [
{
"user" : "user1",
"message" : "My first comment",
"dateCreated" : ISODate("2013-12-10T09:35:00Z"),
"like" : 0
}
]
}
> db.posts.find({},{"title":1,_id:0}).limit(2);
{ "title" : "MongoDB Overview" }
{ "title" : "NoSQL Database" }
MongoDB Skip() Method
Syntax
> db.COLLECTION_NAME.find().limit(NUMBER).skip(NUMBER)
Example
> db.posts.find({},{"title":1,_id:0}).limit(1).skip(1);
{ "title" : "NoSQL Database" }
Comments
Post a Comment
Leave Comment