Complete the code to find all documents in the collection.
db.collection.[1]()The find() method retrieves documents from a MongoDB collection. Using other methods like insert() or update() will not return documents.
Complete the code to avoid the anti-pattern of fetching all documents when only one is needed.
db.collection.[1]({})Using findOne() fetches only one document, which is efficient when you need a single result. Using find() fetches all documents, which can be slow and waste resources.
Fix the error in the query to avoid the anti-pattern of unindexed queries.
db.collection.find({ [1]: 'value' })Queries should use indexed fields to avoid slow scans. Using indexedField ensures the query uses an index, improving performance.
Fill both blanks to avoid the anti-pattern of large documents by projecting only needed fields.
db.collection.find({}, { [1]: 1, [2]: 1 })Projecting only necessary fields like name and email avoids fetching large unnecessary data such as password or largeData, improving query speed and reducing memory use.
Fill all three blanks to avoid the anti-pattern of inefficient updates by using the correct update operator and filter.
db.collection.updateOne({ [1]: '123' }, { [2]: { [3]: 'newValue' } })Use _id to filter the document uniquely. Use the $set operator to update only the specified field fieldToUpdate. This avoids replacing the whole document and improves efficiency.