Convert SELECT * to MongoDB find() Without Projection

Learn how SQL SELECT * translates to a MongoDB find() call without a projection argument, returning all fields from matching documents.

Basic Queries

Detailed Explanation

SELECT * and Full Document Retrieval

When SQL uses SELECT * to retrieve all columns, MongoDB's equivalent is a find() call with no projection argument. Every field stored in matching documents is returned, including the _id field that MongoDB adds automatically.

Example SQL

SELECT * FROM products

Generated MongoDB Query

db.products.find(
  {}
)

Why No Projection?

In MongoDB, omitting the second argument to find() means "return all fields." This is the exact equivalent of SELECT * in SQL. There is no need to enumerate every field, because MongoDB documents are schema-flexible and different documents in the same collection may have different fields.

Performance Considerations

Just like in SQL where SELECT * is discouraged for production queries because it fetches unnecessary data, the same applies in MongoDB. For large documents with many fields or embedded arrays, adding a projection to limit returned fields can significantly reduce network transfer and memory usage.

The _id Field

Unlike SQL primary keys that must be explicitly selected, MongoDB always returns the _id field unless you explicitly exclude it with _id: 0 in the projection. When converting SELECT *, this is a non-issue since all fields are returned anyway.

Use Case

During early-stage migration or exploratory data analysis, developers frequently use SELECT * to inspect the full structure of records. Converting this pattern to MongoDB helps teams verify that their document schema contains all the expected fields from the original SQL tables.

Try It — SQL to MongoDB Query

Open full tool