Practice writing queries to create, read, update, and delete (CRUD) data in both SQL and MongoDB.
A query is a request for data or information from a database. Being proficient at writing queries is a fundamental skill for any developer who works with data. The syntax and approach for querying vary between SQL and NoSQL databases. In SQL, you use the Structured Query Language. The most common query is the `SELECT` statement, which is used to retrieve data. It can be very powerful, allowing you to specify which columns you want (`SELECT column1, column2`), from which table (`FROM my_table`), apply filters (`WHERE condition`), sort the results (`ORDER BY column`), and join multiple tables together (`JOIN other_table`). For modifying data, SQL provides `INSERT` to add new rows, `UPDATE` to change existing rows, and `DELETE` to remove rows. In MongoDB, queries are typically constructed as JSON-like documents. The primary method for reading data is `find()`. You can pass a 'query document' to `find()` to filter the results. For example, `db.users.find({ city: 'London' })` would retrieve all users where the city is London. MongoDB's query language is very expressive, supporting logical operators (`$and`, `$or`), comparison operators (`$gt` for greater than, `$lt` for less than), and the ability to query into nested documents and arrays. For data modification, MongoDB provides methods like `insertOne()`, `updateOne()`, and `deleteOne()`, which also take document-based criteria to specify which documents to affect.