Quiz: Mastering MongoDB Query and Aggregation Practices Quiz

  1. Basic Document Retrieval

    Which query will find all documents in the 'users' collection where the 'age' field is greater than 30?

    1. { age: { $gt: 30 } }
    2. { age: { $lt: 30 } }
    3. { age: { $gte: 30 } }
    4. { age: { $eq: 30 } }
    5. { 'age' u003E 30 }
  2. Updating Multiple Fields

    How would you correctly update both the 'name' and 'email' fields for a single document using the updateOne method?

    1. { $set: { name: 'Sam', email: 'sam@example.com' } }
    2. { set: { name: 'Sam', email: 'sam@example.com' } }
    3. { $update: { name: 'Sam', email: 'sam@example.com' } }
    4. { $set: [ name: 'Sam', email: 'sam@example.com' ] }
    5. { $modify: { name: 'Sam', email: 'sam@example.com' } }
  3. Logical Query Operators

    Which operator is used in MongoDB to combine multiple conditions with a logical AND?

    1. $and
    2. $or
    3. $not
    4. u0026and
    5. $nand
  4. Using Aggregation Framework

    Which aggregation stage allows you to group documents by a specified field and perform accumulations like sum or average?

    1. $group
    2. $sort
    3. $project
    4. $limit
    5. $concat
  5. Querying Embedded Documents

    How would you find documents where the 'address.city' field equals 'London'?

    1. { 'address.city': 'London' }
    2. { address.city = 'London' }
    3. { address: { city: 'London' } }
    4. { address_city: 'London' }
    5. { 'address-city': 'London' }
  6. Array Field Matching

    If you want to find documents with at least one element in the 'tags' array equal to 'active', which query do you use?

    1. { tags: 'active' }
    2. { tags: { $eq: ['active'] } }
    3. { tags: { $contains: 'active' } }
    4. { $in: { tags: 'active' } }
    5. { tags: { $equals: 'active' } }
  7. Aggregation Sorting

    Which aggregation stage is used to sort the output documents by a particular field in descending order?

    1. { $sort: { field: -1 } }
    2. { $order: { field: -1 } }
    3. { $sortBy: { field: -1 } }
    4. { $descending: { field: 1 } }
    5. { $orderby: { field: -1 } }
  8. Field Renaming in Aggregation

    Which aggregation operator allows you to change field names or include/exclude fields in documents?

    1. $project
    2. $rename
    3. $update
    4. $replace
    5. $modify
  9. Querying for Null Values

    How would you retrieve documents in the 'order' collection where the field 'deliveryDate' is missing or set to null?

    1. { deliveryDate: null }
    2. { deliveryDate: { $null: true } }
    3. { deliveryDate: { $isNull: true } }
    4. { deliveryDate = NULL }
    5. { deliveryDate: undefined }
  10. Updating Array Elements

    Which update operator is used to add an item to an array field within a document?

    1. $push
    2. $add
    3. $append
    4. $inc
    5. $arrayAdd