MongoDB Tutorial for Beginners - Find Method and Projection in MongoDB - Part 14

preview_player
Показать описание
Learn How to use Find Method and how to project fields in MongoDB.

Syntax of find method:

Selects documents in a collection and returns a cursor to the selected documents.

query-Optional. Specifies selection filter using query operators. To return all documents in a collection, omit this parameter or pass an empty document ({}).

projection-Optional. Specifies the fields to return in the documents that match the query filter. To return all fields in the matching documents, omit this parameter.

The definition of Projection goes something like this - The projection parameter determines which fields are returned in the matching documents. The projection parameter takes a document of the following form:

{ field1: value, field2: value ... }

The (value) can be any of the following:

1 or true to include the field in the return documents.
0 or false to exclude the field.
Рекомендации по теме