From the course: MongoDB Essential Training

Unlock the full course today

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

Arrays

Arrays

- In this video, we are going to again be using the sample data database and we're going to be looking at the movies collection. So let's just remind ourselves what documents in the movies collection look like. And here we've got an actors array and a genres array. In this video, we're going to talk a bit about how you query with arrays. So if you want to, for example, query movies that should have the genre, let's say, comedy, the way you would do that is you would say db.movies.findOne. Well, let's actually use the normal find command. And then you would specify the genre field to be comedy. It doesn't matter that there is an array here. What mongodb is going to do is it's going to check whether comedy is any value inside the array. So here, for example, we get back multiple documents. If you look at the top one here, it has only one single genre entry, and that's comedy. And the last document here has an array with…

Contents