0
0
MongoDBquery~30 mins

find method basics in MongoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
PMC: find method basics
📖 Scenario: You are managing a small library database. You want to find books by their titles and authors.
🎯 Goal: Build a MongoDB query using the find method to retrieve books from the collection.
📋 What You'll Learn
Create a collection named books with specific book documents
Add a filter variable to search for books by author
Use the find method with the filter to get matching books
Complete the query to return the results as an array
💡 Why This Matters
🌍 Real World
Finding specific records in a database is a common task in apps like libraries, stores, or user management systems.
💼 Career
Knowing how to use the find method in MongoDB is essential for backend developers and data engineers working with NoSQL databases.
Progress0 / 4 steps
1
Create the books collection with documents
Create a variable called books and assign it an array with these exact documents: { title: 'The Hobbit', author: 'J.R.R. Tolkien' }, { title: '1984', author: 'George Orwell' }, and { title: 'To Kill a Mockingbird', author: 'Harper Lee' }.
MongoDB
Need a hint?

Use an array of objects with the exact titles and authors given.

2
Add a filter variable to find books by author
Create a variable called authorFilter and set it to an object that filters books where the author is exactly 'George Orwell'.
MongoDB
Need a hint?

Use an object with the key author and value 'George Orwell'.

3
Use the find method with the filter
Create a variable called resultCursor and assign it the result of calling db.books.find(authorFilter).
MongoDB
Need a hint?

Use db.books.find(authorFilter) exactly as shown.

4
Convert the cursor to an array to get the results
Create a variable called resultArray and assign it the result of calling resultCursor.toArray().
MongoDB
Need a hint?

Use resultCursor.toArray() to get the matching documents as an array.