Sometimes when you query a collection in MongoDB, you might not be happy with the field names. By default, the field names are simply a reflection of the field names in the actual documents.
Perhaps the field names are inconsistent, or there’s a typo. Whatever the reason, you can use the $project
aggregation pipeline stage to rename a field in your query results.
In some ways, this is comparable to using an alias in SQL, as it doesn’t rename the underlying fields, it simply renames them in the query results.
Continue reading →