0% found this document useful (0 votes)
60 views

FIT3176 W4 Lab 03 Activity Sheet 3 MongoDB Text Search

1. The document describes a tutorial on performing text searches in MongoDB using the students collection as an example. It includes sample documents from the students collection with fields like name, address, gender, course, and email address. 2. The tutorial shows how to create a text index on the emailAddress field to enable text searches on that field. It then performs a search to find students using Gmail without needing to know the full email address. 3. Additional steps show searching for off-campus students using Gmail, sorting the results by email address. It also describes connecting to the studentEnrolment database in MongoDB Compass and viewing indexes and explain plans for text searches.

Uploaded by

eddweeb
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)
60 views

FIT3176 W4 Lab 03 Activity Sheet 3 MongoDB Text Search

1. The document describes a tutorial on performing text searches in MongoDB using the students collection as an example. It includes sample documents from the students collection with fields like name, address, gender, course, and email address. 2. The tutorial shows how to create a text index on the emailAddress field to enable text searches on that field. It then performs a search to find students using Gmail without needing to know the full email address. 3. Additional steps show searching for off-campus students using Gmail, sorting the results by email address. It also describes connecting to the studentEnrolment database in MongoDB Compass and viewing indexes and explain plans for text searches.

Uploaded by

eddweeb
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
You are on page 1/ 3

1

Lab 03 Activity Sheet 3


MongoDB Text Search
This tutorial requires you to use the students collection from Tutorial 3a.
ID First Last Address Gender Course Year Off- Email Ad
name name Street Suburb State Postcode Campus
Address
1001 John Smith 123 Clayton VIC 3168 Male BITS 2019 false jsmith@gm
Monash jsmith@ya
Drive
1002 Mary Citizen 900 Caulfield VIC 3145 Female BSE 2018 true mcitizen@
Dandenong East
Road
1003 Fred Bloggs 90 Clayton VIC 3168 Male BITS, 2017 false fredb@gm
Wellington BBIS
Road
1004 Nick Nice 3 Robinson Kew VIC 3080 Male BCS 2018 false nicknice@
Avenue
1005 Wendy Wheat 6 Malvern VIC 3144 Female GDS 2019 true wwheat@y
Algorithm
Street
Table 1 – students collection

Text Search
1. Find the students who are using Gmail.
Can you find it without knowing the full email address?

2. Type the following code:

db.students.createIndex({emailAddress: "text"})

What does the code above do?

It creates a text index for the emailAddress field.

3. Now type in the following code:

db.students.find({$text: {$search: "gmail"}})

Can you find the students who are using Gmail now?

4. Show students who are off-campus students and using Gmail. Sort the result by the email
address in ascending order.
2

5. Open MongoDB Compass, then connect to localhost. In the list of databases, you will
have the studentEnrolment. Select the studentEnrolment database.

6. Currently, you only have the students collection in this database. Select the
students collection and observe the documents inside this collection, including their
data type.

7. Go to the Indexes tab. How many indexes are there? Write down your observations.

8. Go to the Explain Plan tab and type in {$text: {$search: "gmail"}} in the
Filter field. Have a look at the Query Performance Summary.

Write down your observations.


3

The End

You might also like