In MongoDB, which statement best describes the difference between a table in SQL and a collection in MongoDB?
Think about how flexible the data structure is in MongoDB compared to SQL.
Tables in SQL databases have fixed schemas with rows and columns. Collections in MongoDB store documents that can have different fields and structures, allowing more flexibility.
Given a SQL table users with columns id and name, and a MongoDB collection users with documents having fields _id and name, what would be the result of the following MongoDB query?
db.users.find({ name: "Alice" })Assuming the collection has these documents:
[{ _id: 1, name: "Alice" }, { _id: 2, name: "Bob" }, { _id: 3, name: "Alice", age: 30 }]The query filters documents where the name field equals "Alice".
The query returns all documents where the name field is "Alice". Both documents with _id 1 and 3 match, including the one with an extra age field.
Which of the following commands will cause a syntax error when creating a collection in MongoDB?
Look for missing quotes or incorrect argument types.
Option D is invalid because the collection name must be a string enclosed in quotes. Without quotes, it causes a syntax error.
You have a large SQL table and a MongoDB collection both storing user data. Which approach is generally faster for retrieving a user by their unique ID?
Think about how both systems index unique identifiers.
Both SQL tables and MongoDB collections use indexes on unique IDs (_id in MongoDB, primary key in SQL) to quickly retrieve data, making their performance similar for such queries.
A developer tries to enforce a fixed schema in a MongoDB collection by creating a table-like structure with all fields mandatory. Which problem will most likely occur?
Consider MongoDB's schema flexibility and validation behavior by default.
MongoDB collections are schema-less by default, so documents missing some fields are accepted unless explicit validation rules are set. This can lead to inconsistent data if a fixed schema is expected but not enforced.