SlideShare a Scribd company logo
1 of 8
MongoDB Query
Query Document Use Case detailed
Query Document Conditional
db.user.find({"age" : {"$gte" : 8, "$lte" :
23}})
db.user.find({"age" : {"$gte" : 8}})
db.user.find({"age" : {"$gt" : 7}})
db.user.find({"age" : {"$lt" : 23}})
Mongo Variable Operator equivalent
"$lt" <
"$lte" <=
"$gt” >
"$gte" >=
Using null
> db.user.find()
{ "_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"), "date" : ISODate("2013-03-10T11:30:50.555Z"),
"remarks" : [ { "name
" : "anish", "rate" : "good" }, { "name" : "nath", "rate" : "bad" } ], "uName" : "anish" }
{ "_id" : ObjectId("513e1339cb4ee0901c14db28"), "uName" : “ashish", "mName" : "", "date" :
ISODate("2013-03-11T17:23:59.294Z")
}
{ "_id" : ObjectId("513e1340cb4ee0901c14db29"), "uName" : “arjun", "mName" : null, "date" :
ISODate("2013-03-11T17:24:14.971Z
") }
> db.user.find({"mName" : null})
{ "_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"), "date" : ISODate("2013-03-10T11:30:50.555Z"),
"remarks" : [ { "name
" : "anish", "rate" : "good" }, { "name" : "nath", "rate" : "bad" } ], "uName" : "anish" }
{ "_id" : ObjectId("513e1340cb4ee0901c14db29"), "uName" : “arjun", "mName" : null, "date" :
ISODate("2013-03-11T17:24:14.971Z
") }
* doesnot exist also return "$exists“ to rescue
Using null with $EXISTS
> db.user.find({"mName" : {"$in" : [null], "$exists" : true}})
{ "_id" :
ObjectId("513e1340cb4ee0901c14db29"),
"uName" : "anish", "mName" : null, "date" :
ISODate("2013-03-11T17:24:14.971Z
") }
Using $SLICE
> db.user.findOne(){
"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),
"date" : ISODate("2013-03-10T11:30:50.555Z"),
"remarks" : [
{
"name" : "anish",
"rate" : "good"
},
{
"name" : "nath",
"rate" : "bad"
}
],
"uName" : "anish"
}
>db.user.findOne({}, {"remarks" : {"$slice" : -1}})
Will get the last comment
{
"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),
"date" : ISODate("2013-03-10T11:30:50.555Z"),
"remarks" : [
{
"name" : "nath",
"rate" : "bad"
}
],
"uName" : "anish"
}
Using $SLICE
Get the last three comments
> db.user.findOne({}, , {“remarks" :
{"$slice" : -3}}
Get the first three comments
> db.user.findOne({}, , {“remarks" :
{"$slice" : 3}}
CURSOR
SIMILAR to implicit cursor in Oracle, give a
refrence pointer to the results untill fetch
the result will not be stored in the memory
For example : --
> var cursor = db.user.find()
> cursor.forEach(function(x) { print(x._id) } )
ObjectId("513c6ef1cfce9090d3fd8b1d")
ObjectId("513e1339cb4ee0901c14db28")
ObjectId("513e1340cb4ee0901c14db29")
Thanks for Watching
feedback
appreciated………………
…………

More Related Content

What's hot

MongoDB Performance Debugging
MongoDB Performance DebuggingMongoDB Performance Debugging
MongoDB Performance Debugging
MongoDB
 
Getting Started with MongoDB: 4 Application Designs
Getting Started with MongoDB: 4 Application DesignsGetting Started with MongoDB: 4 Application Designs
Getting Started with MongoDB: 4 Application Designs
DATAVERSITY
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
MongoDB
 
Format xls sheets Demo Mode
Format xls sheets Demo ModeFormat xls sheets Demo Mode
Format xls sheets Demo Mode
Jared Bourne
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
Ryousei Takano
 

What's hot (20)

Persistencia de datos con Parse
Persistencia de datos con ParsePersistencia de datos con Parse
Persistencia de datos con Parse
 
Functional reactive android (with Groovy)
Functional reactive android (with Groovy)Functional reactive android (with Groovy)
Functional reactive android (with Groovy)
 
Mongo db updatedocumentusecases
Mongo db updatedocumentusecasesMongo db updatedocumentusecases
Mongo db updatedocumentusecases
 
Mongo db for C# Developers
Mongo db for C# DevelopersMongo db for C# Developers
Mongo db for C# Developers
 
Embedding a language into string interpolator
Embedding a language into string interpolatorEmbedding a language into string interpolator
Embedding a language into string interpolator
 
MongoDB Performance Debugging
MongoDB Performance DebuggingMongoDB Performance Debugging
MongoDB Performance Debugging
 
Getting Started with MongoDB: 4 Application Designs
Getting Started with MongoDB: 4 Application DesignsGetting Started with MongoDB: 4 Application Designs
Getting Started with MongoDB: 4 Application Designs
 
FiiPractic 2015 - Adroid Pro - Day 3 - API Day
FiiPractic 2015 - Adroid Pro - Day 3 - API DayFiiPractic 2015 - Adroid Pro - Day 3 - API Day
FiiPractic 2015 - Adroid Pro - Day 3 - API Day
 
Web client security
Web client securityWeb client security
Web client security
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
 
Format xls sheets Demo Mode
Format xls sheets Demo ModeFormat xls sheets Demo Mode
Format xls sheets Demo Mode
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
PostgreSQLからMongoDBへ
PostgreSQLからMongoDBへPostgreSQLからMongoDBへ
PostgreSQLからMongoDBへ
 
MongoDB
MongoDBMongoDB
MongoDB
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
 
2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky
 
How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL Superpowers
 
Mongo db for c# developers
Mongo db for c# developersMongo db for c# developers
Mongo db for c# developers
 

Viewers also liked

Mongo db introduction
Mongo db introductionMongo db introduction
Mongo db introduction
zarigatongy
 
Informações blog
Informações  blogInformações  blog
Informações blog
Cluqui
 

Viewers also liked (20)

Basic crud operation
Basic crud operationBasic crud operation
Basic crud operation
 
Big data references
Big data referencesBig data references
Big data references
 
Mongo db readingdocumentusecases
Mongo db readingdocumentusecasesMongo db readingdocumentusecases
Mongo db readingdocumentusecases
 
Mongo db index
Mongo db indexMongo db index
Mongo db index
 
Mongo db datatypes
Mongo db datatypesMongo db datatypes
Mongo db datatypes
 
Mongo db introduction
Mongo db introductionMongo db introduction
Mongo db introduction
 
Mongo db pagination
Mongo db paginationMongo db pagination
Mongo db pagination
 
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETFDhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
 
The Point to Point Protocol (PPP)
The Point to Point Protocol (PPP)The Point to Point Protocol (PPP)
The Point to Point Protocol (PPP)
 
RADIUS- Packet Example/Vendors
RADIUS- Packet Example/Vendors RADIUS- Packet Example/Vendors
RADIUS- Packet Example/Vendors
 
Top 10 programming langauges crossed decades
Top 10 programming langauges crossed decadesTop 10 programming langauges crossed decades
Top 10 programming langauges crossed decades
 
Password Authentication Protocol
Password Authentication ProtocolPassword Authentication Protocol
Password Authentication Protocol
 
Regular Expression
Regular Expression Regular Expression
Regular Expression
 
(Aes )ADVANCED ENCRYPTION STANDARD
(Aes )ADVANCED ENCRYPTION STANDARD(Aes )ADVANCED ENCRYPTION STANDARD
(Aes )ADVANCED ENCRYPTION STANDARD
 
Jvm architecture Method Area
Jvm architecture Method AreaJvm architecture Method Area
Jvm architecture Method Area
 
Quick sort demo
Quick sort demoQuick sort demo
Quick sort demo
 
Witch & wizard 01 condenados
Witch & wizard 01 condenadosWitch & wizard 01 condenados
Witch & wizard 01 condenados
 
La lengua y su organización, lengua, signo lingüístico 3ºeso
La lengua y su organización, lengua, signo lingüístico 3ºesoLa lengua y su organización, lengua, signo lingüístico 3ºeso
La lengua y su organización, lengua, signo lingüístico 3ºeso
 
Las perífrasis verbales
Las perífrasis verbalesLas perífrasis verbales
Las perífrasis verbales
 
Informações blog
Informações  blogInformações  blog
Informações blog
 

Similar to Mongo db query docuement

MongoDB (Advanced)
MongoDB (Advanced)MongoDB (Advanced)
MongoDB (Advanced)
TO THE NEW | Technology
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analytics
MongoDB
 

Similar to Mongo db query docuement (20)

MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
 
Elasticsearch in 15 minutes
Elasticsearch in 15 minutesElasticsearch in 15 minutes
Elasticsearch in 15 minutes
 
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDBMongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB
MongoDB MongoDB
MongoDB
 
Practical MongoDB
Practical MongoDBPractical MongoDB
Practical MongoDB
 
ElasticSearch - Introduction to Aggregations
ElasticSearch - Introduction to AggregationsElasticSearch - Introduction to Aggregations
ElasticSearch - Introduction to Aggregations
 
MongoDB (Advanced)
MongoDB (Advanced)MongoDB (Advanced)
MongoDB (Advanced)
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
 
jQuery Datatables With MongDb
jQuery Datatables With MongDbjQuery Datatables With MongDb
jQuery Datatables With MongDb
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
 
MongoD Essentials
MongoD EssentialsMongoD Essentials
MongoD Essentials
 
Mongo db mug_2012-02-07
Mongo db mug_2012-02-07Mongo db mug_2012-02-07
Mongo db mug_2012-02-07
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Mongo db 101 dc group
Mongo db 101 dc groupMongo db 101 dc group
Mongo db 101 dc group
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analytics
 
아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 

Recently uploaded

Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service HaridwarHaridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
ranekokila
 
Models in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl ServiceModels in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl Service
Monica Sydney
 
Dubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiDubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in Dubai
Monica Sydney
 
Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girls
Monica Sydney
 

Recently uploaded (20)

Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service HaridwarHaridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
 
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyHire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
 
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
 
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
 
Turbhe Female Escorts 09167354423 Turbhe Escorts,Call Girls In Turbhe
Turbhe Female Escorts 09167354423  Turbhe Escorts,Call Girls In TurbheTurbhe Female Escorts 09167354423  Turbhe Escorts,Call Girls In Turbhe
Turbhe Female Escorts 09167354423 Turbhe Escorts,Call Girls In Turbhe
 
Call 8617370543 Sangli Call girls with real photos and phone numbers
Call 8617370543 Sangli Call girls with real photos and phone numbersCall 8617370543 Sangli Call girls with real photos and phone numbers
Call 8617370543 Sangli Call girls with real photos and phone numbers
 
Prayagraj College Girls Escorts 8250092165 Short 1500 Night 6000 Best call g...
Prayagraj College Girls Escorts  8250092165 Short 1500 Night 6000 Best call g...Prayagraj College Girls Escorts  8250092165 Short 1500 Night 6000 Best call g...
Prayagraj College Girls Escorts 8250092165 Short 1500 Night 6000 Best call g...
 
Bhubaneswar🌹Patia ❤CALL GIRLS 0000000000 💟 CALL GIRLS IN bhubaneswar ESCORT S...
Bhubaneswar🌹Patia ❤CALL GIRLS 0000000000 💟 CALL GIRLS IN bhubaneswar ESCORT S...Bhubaneswar🌹Patia ❤CALL GIRLS 0000000000 💟 CALL GIRLS IN bhubaneswar ESCORT S...
Bhubaneswar🌹Patia ❤CALL GIRLS 0000000000 💟 CALL GIRLS IN bhubaneswar ESCORT S...
 
Models in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl ServiceModels in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl Service
 
Deira Call girls 0507330913 Call girls in Deira
Deira Call girls 0507330913 Call girls in DeiraDeira Call girls 0507330913 Call girls in Deira
Deira Call girls 0507330913 Call girls in Deira
 
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls AgencyHire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
 
Call Girls Bijapur - 9332606886 Rs 3000 Free Pickup & Drop Services 24x448
Call Girls Bijapur - 9332606886 Rs 3000 Free Pickup & Drop Services 24x448Call Girls Bijapur - 9332606886 Rs 3000 Free Pickup & Drop Services 24x448
Call Girls Bijapur - 9332606886 Rs 3000 Free Pickup & Drop Services 24x448
 
Dubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiDubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in Dubai
 
Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girls
 
Deira Call girl 0506129535 Independent Call girl in Deira
Deira Call girl 0506129535  Independent Call girl in DeiraDeira Call girl 0506129535  Independent Call girl in Deira
Deira Call girl 0506129535 Independent Call girl in Deira
 
Osmanabad Call Girls Book Night 4k to 12k ️[8617370543] Escorts Girls Service
Osmanabad Call Girls Book Night 4k to 12k ️[8617370543] Escorts Girls ServiceOsmanabad Call Girls Book Night 4k to 12k ️[8617370543] Escorts Girls Service
Osmanabad Call Girls Book Night 4k to 12k ️[8617370543] Escorts Girls Service
 
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
 
Call Girls Rajnandgaon / 9332606886 Genuine Call girls with real Photos and N...
Call Girls Rajnandgaon / 9332606886 Genuine Call girls with real Photos and N...Call Girls Rajnandgaon / 9332606886 Genuine Call girls with real Photos and N...
Call Girls Rajnandgaon / 9332606886 Genuine Call girls with real Photos and N...
 
Pakistani Call girls in Ajman 0505086370 Ajman Call girls
Pakistani Call girls in Ajman 0505086370 Ajman Call girlsPakistani Call girls in Ajman 0505086370 Ajman Call girls
Pakistani Call girls in Ajman 0505086370 Ajman Call girls
 
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and ModelMandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
 

Mongo db query docuement

  • 1. MongoDB Query Query Document Use Case detailed
  • 2. Query Document Conditional db.user.find({"age" : {"$gte" : 8, "$lte" : 23}}) db.user.find({"age" : {"$gte" : 8}}) db.user.find({"age" : {"$gt" : 7}}) db.user.find({"age" : {"$lt" : 23}}) Mongo Variable Operator equivalent "$lt" < "$lte" <= "$gt” > "$gte" >=
  • 3. Using null > db.user.find() { "_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"), "date" : ISODate("2013-03-10T11:30:50.555Z"), "remarks" : [ { "name " : "anish", "rate" : "good" }, { "name" : "nath", "rate" : "bad" } ], "uName" : "anish" } { "_id" : ObjectId("513e1339cb4ee0901c14db28"), "uName" : “ashish", "mName" : "", "date" : ISODate("2013-03-11T17:23:59.294Z") } { "_id" : ObjectId("513e1340cb4ee0901c14db29"), "uName" : “arjun", "mName" : null, "date" : ISODate("2013-03-11T17:24:14.971Z ") } > db.user.find({"mName" : null}) { "_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"), "date" : ISODate("2013-03-10T11:30:50.555Z"), "remarks" : [ { "name " : "anish", "rate" : "good" }, { "name" : "nath", "rate" : "bad" } ], "uName" : "anish" } { "_id" : ObjectId("513e1340cb4ee0901c14db29"), "uName" : “arjun", "mName" : null, "date" : ISODate("2013-03-11T17:24:14.971Z ") } * doesnot exist also return "$exists“ to rescue
  • 4. Using null with $EXISTS > db.user.find({"mName" : {"$in" : [null], "$exists" : true}}) { "_id" : ObjectId("513e1340cb4ee0901c14db29"), "uName" : "anish", "mName" : null, "date" : ISODate("2013-03-11T17:24:14.971Z ") }
  • 5. Using $SLICE > db.user.findOne(){ "_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"), "date" : ISODate("2013-03-10T11:30:50.555Z"), "remarks" : [ { "name" : "anish", "rate" : "good" }, { "name" : "nath", "rate" : "bad" } ], "uName" : "anish" } >db.user.findOne({}, {"remarks" : {"$slice" : -1}}) Will get the last comment { "_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"), "date" : ISODate("2013-03-10T11:30:50.555Z"), "remarks" : [ { "name" : "nath", "rate" : "bad" } ], "uName" : "anish" }
  • 6. Using $SLICE Get the last three comments > db.user.findOne({}, , {“remarks" : {"$slice" : -3}} Get the first three comments > db.user.findOne({}, , {“remarks" : {"$slice" : 3}}
  • 7. CURSOR SIMILAR to implicit cursor in Oracle, give a refrence pointer to the results untill fetch the result will not be stored in the memory For example : -- > var cursor = db.user.find() > cursor.forEach(function(x) { print(x._id) } ) ObjectId("513c6ef1cfce9090d3fd8b1d") ObjectId("513e1339cb4ee0901c14db28") ObjectId("513e1340cb4ee0901c14db29")