Using cursors, you can control the results of a query:
Cursors implement an iterator interface that can be used in foreach ():
When a query is assigned a variable, find () does not immediately query the database. For example: Var cursor=db.test.find (). Queries are sent to the database only when Cursor.hasnext () is executed. Therefore, some query filtering conditions are added before the query.
Limit () function: it specifies the upper limit. Find () By default, returns only the previous 20 results, by using the limit () function, you can limit the returned results, ignore a certain number of results, and sort them. These operations must be performed before they are sent to the database.
Skip () function: Skips the specified number of documents, returns the remaining documents, and does not return any documents if the number of files in the collection is less than the specified number.
Sort () function: Takes a set of key-value pairs as parameters, where the key is the key value in the document, and the value represents the direction of the sort. Where 1 means ascending, 1 indicates descending order.
If more than one key is specified, the keys are sorted in the order specified:
Key-Value comparison priority (from small to Large):
Minimum –>null–> number (integer/Long integer/Double) –> string –> Object/document –> array –> binary Data –> object id–> boolean –> datetime –> timestamp –> Regular Expression- > Maximum Value