Urgent: Critical question from Chapter 5 on $merge

In the chapter 5 video of merge, at this time frame:

You can see that they created two pipelines - mflix_pipeline and mfreindbook_pipeline.

At the bottom of the video, you can see the aggregate query being:

db.users.aggregate(mflix_pipeline) & db.users.aggregate(mfirendbook_pipeline)

Shouldn’t it be :

db.mflix.aggregate(mflix_pipeline) — because in the merge syntax the target is specified as “sv.users”

Look at the video at the current time and please explain!

Hi @Vivek_Poddar,
Please note that the syntax for executing a aggregation pipeline is as below:

db.<collection-name>.aggregate(<aggreagtion-pipeline>)

Since, there are no collections named as mflix(Please note it is the database name, which infact is sample_mflix and not mflix).
Therefore, the following queries are correct:

db.users.aggregate(mflix_pipeline) 
db.users.aggregate(mfirendbook_pipeline)

I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Then, @SourabhBagrecha how is the below query supposed to work?

Suppose, mflix_pipeline = [ { $project: {_id: “$username”, mflix: “$$ROOT”} } ]

How does it know that from which database and which collection does it have to merge with the target?

Hi @Vivek_Poddar,

Please note that the mflix_pipeline is the name of the variable. It never implies the name of the database. You always have to switch to the appropriate database before executing any command on the concerned database.
Therefore, you are required to execute the following command before the aggregate() command:

use sample_mflix

and then

db.users.aggregate(mflix_pipeline)

I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer