Test Yourself: CRUD Operations

Test your understanding of the CRUD operations.

1

How can we use the following handler to retrieve all the files?

exports.searchFiles = async (req, res) => {
  try {
    const filter = {};

    if (req.query.name) filter.name = /req.query.name/;
    if (req.query.description) filter.description = /req.query.description/;
    if (req.query.createdAt) filter.createdAt = req.query.createdAt;

    const files = await File.find(filter);

    res
      .status(200)
      .json({ message: "Files retrieved successfully", data: files });
  } catch (err) {
    console.log(err);
    return res.status(500).send(err.message);
  }
};
A)

Hit the /file route with the name="" query parameter.

B)

Hit the /file route with the description="" query parameter.

C)

Hit the /file route with the createdAt="" query parameter.

D)

Hit the /file route without any query parameters.

Question 1 of 50 attempted

Get hands-on with 1400+ tech skills courses.