Complete the code to find all books that a specific author wrote by matching the author's ID.
db.books.find({ authors: [1] })The query filters books where the authors array contains the specific author ID. Replace {{BLANK_1}} with the correct author ID string.
Complete the code to add a new author ID to a book's authors array using the $push operator.
db.books.updateOne({ _id: bookId }, { $push: { authors: [1] } })The $push operator adds a single element to the array. The author ID must be a string, so it needs quotes.
Fix the error in the aggregation pipeline stage to lookup authors for each book.
{ $lookup: { from: "authors", localField: "authors", foreignField: [1], as: "authorDetails" } }The foreignField should be the field in the authors collection that matches the IDs stored in the books' authors array. Usually, this is _id.
Fill both blanks to create a query that finds authors who wrote a book with a specific title.
db.authors.find({ _id: { $in: db.books.findOne({ title: [1] }).[2] }) })The query finds the book by title, then uses the authors array field to find matching author IDs.
Fill all three blanks to create an aggregation pipeline that joins books with authors and filters books published after 2010.
[ { $match: { year: { $[1]: [2] } } }, { $lookup: { from: "authors", localField: "authors", foreignField: [3], as: "authorInfo" } } ]The $match stage filters books where the year is greater than 2010 using $gt. The $lookup joins authors by matching the _id field.