Mongodb $replaceRoot

found mergeObjects and replaceRoot aggregation methods

in order to merge collections.

examples of official documents are copied down and modified and found that there are no errors available, but there are a few areas that I do not understand. Please refer to you

.

related codes

replaceRoot1 = {"$replaceRoot": {"newRoot": {"$mergeObjects": [{"$arrayElemAt": ["$recharge", 0]}, "$$ROOT"]}}}
replaceRoot2 = {"$replaceRoot": {"newRoot": {"$mergeObjects": [{"$arrayElemAt": ["$consume", 0]}, "$$ROOT"]}}}
-sharp replaceRoot 
-sharp mergeObjects 
-sharp arrayElemAt 
What is the format of

$replaceRoot , and what do newRoot and $ROOT mean?

May.10,2021

check the document:

Menu