Retrieve the data from Mongo DB by passing the array documents


Initial data in DB
{  "Student_name" : "Raja",  "Department" : "Computer Science and Engg",  "Marks" : [69, 78, 88,95]  }
{  "Student_name" : "Rahul",  "Department" : "Computer Science and Engg", "Marks" : [59, 74, 80]  }
{  "Student_name" : " Bittu ",  "Department" : "Computer Science and Engg",  "Marks" : [99, 95, 84,69]  }

Finding the details by passing the exact values of the array to the find command.

db.studentDetails.find({Marks:[59,74,80]})


The above Query returns the second row of the Data Showed above



Retrieving the data by passing at least one matched value to the find command.

db.studentDetails.find({Marks:95})


The above Query returns the first and third row of the data Showed above

Retrieving the data by passing the index of the array and its value to the find command, here we use Dot Notation to get the resultant values.



db.studentDetails.find({'Marks.0':69})

The above Query returns the first row of the data Showed above, Here marks is the Key and Zero is the array index value and 69 is the value provide to be in the Zeroth index of Marks array.

Retrieving the data by passing the values to the $lt and $gt.


db.studentDetails.find({'Marks':{$gt:90,$lt:95}})

The above Query returns the first and third rows because, second row doesn’t have the values between 90 and 95.