@@ -1249,6 +1249,29 @@ Mongoid also has some helpful methods on criteria.
12491249 Band.exists?
12501250 Band.where(name: "Photek").exists?
12511251
1252+ * - ``Criteria#fifth``
1253+
1254+ *Get the fifth document for the given criteria.*
1255+
1256+ *This method automatically adds a sort on _id if no sort is given.*
1257+
1258+ -
1259+ .. code-block:: ruby
1260+
1261+ Band.fifth
1262+
1263+ * - ``Criteria#fifth!``
1264+
1265+ *Get the fifth document for the given criteria, or raise an error if
1266+ none exist.*
1267+
1268+ *This method automatically adds a sort on _id if no sort is given.*
1269+
1270+ -
1271+ .. code-block:: ruby
1272+
1273+ Band.fifth!
1274+
12521275 * - ``Criteria#find_by``
12531276
12541277 *Find a document by the provided attributes. If not found,
@@ -1314,6 +1337,20 @@ Mongoid also has some helpful methods on criteria.
13141337 Band.where(:members.with_size => 3).last
13151338 Band.first(2)
13161339
1340+ * - ``Criteria#first!|last!``
1341+
1342+ *Finds a single document given the provided criteria, or raises an error
1343+ if none are found. This method automatically adds a sort on _id if no
1344+ sort is given. This can cause performance issues, so if the sort is
1345+ undesirable, Criteria#take! can be used instead.*
1346+
1347+ -
1348+ .. code-block:: ruby
1349+
1350+ Band.first!
1351+ Band.where(:members.with_size => 3).first!
1352+ Band.where(:members.with_size => 3).last!
1353+
13171354 * - ``Criteria#first_or_create``
13181355
13191356 *Find the first document by the provided attributes, and if not found
@@ -1361,6 +1398,29 @@ Mongoid also has some helpful methods on criteria.
13611398 # MongoDB 4.2 and lower
13621399 Band.for_js("this.name = param", param: "Tool")
13631400
1401+ * - ``Criteria#fourth``
1402+
1403+ *Get the fourth document for the given criteria.*
1404+
1405+ *This method automatically adds a sort on _id if no sort is given.*
1406+
1407+ -
1408+ .. code-block:: ruby
1409+
1410+ Band.fourth
1411+
1412+ * - ``Criteria#fourth!``
1413+
1414+ *Get the fourth document for the given criteria, or raise an error if
1415+ none exist.*
1416+
1417+ *This method automatically adds a sort on _id if no sort is given.*
1418+
1419+ -
1420+ .. code-block:: ruby
1421+
1422+ Band.fourth!
1423+
13641424 * - ``Criteria#length|size``
13651425
13661426 *Same as count but caches subsequent calls to the database*
@@ -1427,6 +1487,52 @@ Mongoid also has some helpful methods on criteria.
14271487 Band.all.pluck(:name, :likes)
14281488 #=> [ ["Daft Punk", 342], ["Aphex Twin", 98], ["Ween", 227] ]
14291489
1490+ * - ``Criteria#second``
1491+
1492+ *Get the second document for the given criteria.*
1493+
1494+ *This method automatically adds a sort on _id if no sort is given.*
1495+
1496+ -
1497+ .. code-block:: ruby
1498+
1499+ Band.second
1500+
1501+ * - ``Criteria#second!``
1502+
1503+ *Get the second document for the given criteria, or raise an error if
1504+ none exist.*
1505+
1506+ *This method automatically adds a sort on _id if no sort is given.*
1507+
1508+ -
1509+ .. code-block:: ruby
1510+
1511+ Band.second!
1512+
1513+ * - ``Criteria#second_to_last``
1514+
1515+ *Get the second to last document for the given criteria.*
1516+
1517+ *This method automatically adds a sort on _id if no sort is given.*
1518+
1519+ -
1520+ .. code-block:: ruby
1521+
1522+ Band.second_to_last
1523+
1524+ * - ``Criteria#second_to_last!``
1525+
1526+ *Get the second to last document for the given criteria, or raise an
1527+ error if none exist.*
1528+
1529+ *This method automatically adds a sort on _id if no sort is given.*
1530+
1531+ -
1532+ .. code-block:: ruby
1533+
1534+ Band.second_to_last!
1535+
14301536 * - ``Criteria#take``
14311537
14321538 *Get a list of n documents from the database or just one if no parameter
@@ -1474,6 +1580,52 @@ Mongoid also has some helpful methods on criteria.
14741580 # expands out to "managers.name" in the query:
14751581 Band.all.tally('managers.n')
14761582
1583+ * - ``Criteria#third``
1584+
1585+ *Get the third document for the given criteria.*
1586+
1587+ *This method automatically adds a sort on _id if no sort is given.*
1588+
1589+ -
1590+ .. code-block:: ruby
1591+
1592+ Band.third
1593+
1594+ * - ``Criteria#third!``
1595+
1596+ *Get the third document for the given criteria, or raise an error if
1597+ none exist.*
1598+
1599+ *This method automatically adds a sort on _id if no sort is given.*
1600+
1601+ -
1602+ .. code-block:: ruby
1603+
1604+ Band.third!
1605+
1606+ * - ``Criteria#third_to_last``
1607+
1608+ *Get the third to last document for the given criteria.*
1609+
1610+ *This method automatically adds a sort on _id if no sort is given.*
1611+
1612+ -
1613+ .. code-block:: ruby
1614+
1615+ Band.third_to_last
1616+
1617+ * - ``Criteria#third_to_last!``
1618+
1619+ *Get the third to last document for the given criteria, or raise an
1620+ error if none exist.*
1621+
1622+ *This method automatically adds a sort on _id if no sort is given.*
1623+
1624+ -
1625+ .. code-block:: ruby
1626+
1627+ Band.third_to_last!
1628+
14771629
14781630Eager Loading
14791631=============
0 commit comments