$mergeObjects
Combines multiple documents into a single document, merging fields from the input documents with later documents overriding fields from earlier documents.
Syntax
{ $mergeObjects: [<expression1>, <expression2>, ...] }
Parameters
expressions
objectrequiredArray of expressions that resolve to documents to be merged
Examples
Merge two documents
Combine two document objects into one
Query:
db.products.aggregate([{ $project: { merged: { $mergeObjects: ["$details", "$specifications"] } } }])
Output:
Document with merged field containing combined details and specifications