Calling the find function on a particular collection retrieves all the documents, and all the documents include all the properties. Now sometimes you may want to restrict the number of documents based on certain criteria or restrict the properties that you want to view. This is called selection and projection. The first parameter is an object representing the criteria that you want to use for selection. Now we'll come back on that in few minutes, but first we will see how to do a projection. The second parameter here is the projection.
For example, if you want to retrieve only the first name, last name and city of the people in your contact list, then you can simply say here, first name is one, last name is one, and then city is one. To insert one we can also use any nonzero number so zero represents false nonzero represents true. In fact, you can also type the JavaScript keyword true to say that include this particular property when I save this, and then execute the same thing. If I execute Mongo, and then pass on the E zero T dot j s, you will see, only certain properties are being retrieved, and especially First Name, Last Name city. Now by default, the underscore ID is always included. If you don't want that, you can come back to your command and then say underscore ID is false, or zero.
So save it and run the same command again, and you can see that we get only first name, last name and city, if it exists. If the document does not contain a specific property, that property will not be included. And if it doesn't contain any matching property, just an empty object is being written one very Important point that you have to remember is you cannot have a combination of inclusion and exclusion, except for the underscore ID. Apart from the ID if you use inclusion for the properties like one or nonzero or true, you may not be able to specify fonts for other fields. For example, if I try this, we get an error saying that projection cannot have a mix of inclusion and exclusion. So either exclude all the fields that are mentioned here and refer to the remaining ones or include only these fields and do not get any other fees from the documents.