[00:00] In order to fetch documents from Mongo collections, we're going to use the db employees find and find one methods. Find, we've seen before, it returns multiple documents. Find one is going to return a single document. Now, if we don't provide the query, so the criteria that would specify which exact documents should be returned, then Mongo is just going to either get the first one or get all documents that exist in this collection. So if we want to make it more specific, then we need to provide the query parameter and the query is going to relate to all the properties that we got here.
[00:42] So let's use the name property. And here, the first one that we've got over here the document has the name property with Alice Smith value so let's just pass Alice Smith now after running the exact value of the property then we can see that yes it has been found and it's been returned. However sometimes we would like to make it let's say more general so let's say everything that starts with Ali or anything that includes Ali or whatever so sometimes we can use the exact value as we have used over here or we can pass a nested object in order to process it somehow. So now we're going to specify a regex but this is not a property over here this is an operation that we're going to pass to the query and for this reason this is just a convention it starts with a dollar so the regex itself is going to be the ali So there is only one result because we have executed find one. Maybe there are more documents that match this query.
[01:55] So if we wanted to run something similar, and let's say that we wanted to grab the documents that have the personal info and then the email has the example.com domain then we would use a slightly similar approach and that would be that there is an example.com. The regex ends with the example.com. But now here, this is not going to be the name. We need to walk into the personalinfo.email. And what we can do is basically to pass a string over here so personal info now I need to make sure that I don't make a typo personal info dot email and that should do the job So since we are asking only for one document then there is only one response.
[02:52] However, if we replace find one with find then that's going to be a whole collection and we can see that there is quite a bunch of these objects. Now let's query not by a simple string value, whether it's position, name, email, or whatever, let's query by an array. So we're going to run db employees find, and let's now provide the skills. So let's relate to the skills property, which is an array. And we don't want to provide a very exact value.
[03:31] Let's say that we want to filter for any document that will include a value over here. So again, this is an operation within the Mongo query language. So this basically means that any document that under the skills property would have anything that we pass over here. So let's say that we care about JavaScript. So any document that does include JavaScript inside the skills, which should be an array implicitly, would be returned.
[04:06] So here we can see that there is one to two documents that have it. So Alice Smith has JavaScript and Grace Hopper also have JavaScript. Now let's relate to the age property and in this case we would like to specify a certain value so let's say 35 so there is one document that matches this criteria Bob Johnson. Now again if we don't want to make this very let's say explicit value but we wanted to make it let's say anything that is different not equal to a value let's say anybody that has different age than 35 so here we would have quite a bunch of these so 38 age 32 age so everything is different than 35 itself but we can also use things like less than less than or equal greater than greater than or equal etc etc So I'm just going to run lt less than and we can see that there is 32, there is 27 and so on and so forth.