From the course: MongoDB Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

$merge and $out

$merge and $out

- [Instructor] The $out stage allows you to store the results of an aggregation pipeline in a new collection. Let's look inside of these pipes to see what happens as documents pass through this pipeline. Okay, now let's try the $out stage on the terminal. Okay, if you followed along here, we're actually just going to press up and use the pipeline we used in the last video to use with the $out operator. And what we're going to do is we're just going to add another stage at the end of this pipeline. That's going to be our $out stage. The $out stage takes as its argument a document. Inside the document is going to be a db argument, which is the database. For us that will be sample_data. And a collection argument, which for us will be purple. Or it could be anything else. I'll say it's called purple. All right. Now, if I run this, this should create a collection called purple, which will contain all purple cars.…

Contents