find() - Find JSON document command

Find JSON documents according to filter criteria. You can also specify fields to be included or excluded, determine the sort order, limit the number of documents, and page through results with an offset.

Syntax diagram

Read syntax diagramSkip visual syntax diagramdb.collection. find( query,select.sortsort.limitlimit.skipoffset )

Command parameters

query
This optional parameter specifies a filter for selecting a subset of documents.
select
This optional parameter specifies fields to include or exclude in the query.
sort sort
This optional parameter specifies a JSON object that indicates the sort criteria:
1
Sort by ascending order.
-1
Sort by descending order.
This parameter can include the data type, including $int, $long, $number, $date, $timestamp, $string: length, and $binary: length.
limit limit
This optional parameter specifies a JSON object that restricts the number of documents.
offset offset
This optional parameter specifies a JSON object that indicates the number of rows to skip.

Example

Find books in a collection. The collection name is case-sensitive.
db.books.find()
Sample output is as follows:
Row 1:
{
"_id":{"$oid":"519b8727cd1552ed65b47a20"},
"isbn":"123-456-789",
"author":"Verne, Jules",
"title":"Journey to the Center of the Earth",
"abstract":"Classic science fiction novel in an unusual setting",
"price":6,
"pages":276,
"category":"Fantasy",
"sales": 500.5
}