0% found this document useful (0 votes)
19 views1 page

MongoDB Question

The document outlines a series of MongoDB operations for managing a 'student' collection, including creating documents, inserting multiple entries, and displaying specific documents based on various criteria. It also details how to update documents, manipulate array fields, and perform geospatial and text searches. Additionally, it includes aggregate queries for calculating average income based on age and admission type, as well as filtering and sorting results.

Uploaded by

npavitra082
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

MongoDB Question

The document outlines a series of MongoDB operations for managing a 'student' collection, including creating documents, inserting multiple entries, and displaying specific documents based on various criteria. It also details how to update documents, manipulate array fields, and perform geospatial and text searches. Additionally, it includes aggregate queries for calculating average income based on age and admission type, as well as filtering and sorting results.

Uploaded by

npavitra082
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Create a collection “student” and insert a document with the following fields:

"usn":,"name":,"fathername":,"mothername":,"hobbies[],"admissiontype":,"age":,"income":,"
skills":[],"place":,"location":{"type":"Point","coordinates":[, ]},"college":,"comments":})
Insert at least 4 more documents using insertMany() function to the “student” collection
with above mentioned fields:
Display all the documents in the collection:
Display the document of “usn”:1 in the collection:
Display only the first two documents in the collection:
Display the 2nd and 3rd document in the collection:
Display the document of “usn”:1 in the collection and project only the “usn” and
“name” of the document:
Update the document of “usn”:1 by setting a new array field “mark”: to the document:
Display the document of “usn”:1
From the document of “usn”:1 pop the last element from the array field “marks”:
Display the document of “usn”:1
To the document of “usn”:1 push’ 66’ to the array field “marks”:
Update the document of “usn”:2 by setting a new array field “mark”: to the document:
Display the document of “usn”:2
Display all the documents where the “marks” field is greater than ‘99’
Display all the documents where the “marks” field is greater than ‘99’ and less than ‘70’
Update all the documents by pushing two more array elements: ["baking","surfing"] to
the “hobbies”: array field
Display all the documents in the collection:
Update the document of “usn”:1 by pushing two more array elements ["it","testing"] to
the “skills”: array field by SORTING it in ascending order
Create an 2dshpere index for the “location”: field
Write a geospatial query to find the nearby location with maximum distance of 10000
meters (for the “location”: field)
Create a Text Index for the “comments”: field and search using some “keyword”
Text search using some “keyword” AND exclude some “keyword” for the “comments”:
Write aggregate query to find the average income by grouping based on “age”: field
Write aggregate query to find the average income by grouping based on
“admissiontype”: field
Write a pipeline aggregate query to find the documents with “age”: greater than 25,
sort it based on “age”: skip the first document and project only the
fields,”usn”:,”name”:,”age”:

You might also like