From the course: MongoDB Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
$function - MongoDB Tutorial
From the course: MongoDB Essential Training
$function
- [Instructor] There is one pipeline operator, which you can program to be whatever you need it to be. The $function pipeline operator allows you to write JavaScript functions that operate on the field values in your documents. Let's try that out. I'm going to use the movies collection for this example. So let's briefly remind ourselves what the documents in that one look like. All right, as you can see, the actors field value is an array of actors. However, that array is not alphabetically sorted. If we wanted it to be alphabetically sorted, that's where we can use $function, for example. All right, so let's try that. I'm going to specify the movies collection and then call the aggregate method on it. As usual, I'm going to pass an array to the aggregate method and the array will contain our stages, in our case, just the one stage and we're going to use the project stage. The $function operator is just an operator…
Contents
-
-
-
-
-
-
-
An overview of stages1m 47s
-
(Locked)
$group4m 14s
-
(Locked)
$bucket5m 15s
-
(Locked)
$unwind3m 18s
-
(Locked)
$merge and $out3m 59s
-
(Locked)
$function3m 27s
-
(Locked)
$lookup4m 44s
-
(Locked)
Performance10m 38s
-
(Locked)
Challenge: Write aggregation pipelines24s
-
(Locked)
Solution: Write aggregation pipelines5m 18s
-
-
-
-