Python -Tutorial

Python-HOME Python-Einführung Python-Erste Schritte Python-Syntax Python-Kommentare Python-Variablen Python-Datentypen Python-Zahlen Python-Casting Python-Strings Python-Booleans Python-Operatoren Python-Listen Python-Tupel Python-Sets Python-Wörterbücher Python Wenn ... Sonst Python-While-Schleifen Python-For-Schleifen Python-Funktionen Python-Lambda Python-Arrays Python-Klassen/Objekte Python-Vererbung Python-Iteratoren Python-Bereich Python-Module Python-Daten Python-Mathematik Python-JSON Python-RegEx Python-PIP Python Versuchen ... Außer Python-Benutzereingabe Formatierung von Python-Strings

Umgang mit Dateien

Umgang mit Python-Dateien Python-Dateien lesen Python-Dateien schreiben/erstellen Python-Dateien löschen

Python-Module

NumPy-Tutorial Panda-Komplettlösung Scipy-Tutorial

Python-Matplotlib

Matplotlib-Einführung Matplotlib loslegen Matplotlib-Pyplot Matplotlib-Plotten Matplotlib-Marker Matplotlib-Linie Matplotlib-Labels Matplotlib-Raster Matplotlib-Subplots Matplotlib-Scatter Matplotlib-Bars Matplotlib-Histogramme Matplotlib-Kreisdiagramme

Maschinelles Lernen

Einstieg Mittlerer Medianmodus Standardabweichung Perzentil Datenverteilung Normale Datenverteilung Streudiagramm Lineare Regression Polynomiale Regression Mehrfache Regression Skala Trainieren/Testen Entscheidungsbaum

Python-MySQL

MySQL-erste Schritte MySQL-Datenbank erstellen MySQL-Tabelle erstellen MySQL-Einfügung MySQL-Auswahl MySQL-Wo MySQL-Reihenfolge nach MySQL löschen MySQL-Drop-Tabelle MySQL-Update MySQL-Limit MySQL-Beitritt

Python-MongoDB

Beginnen Sie mit MongoDB MongoDB Datenbank erstellen MongoDB-Create-Sammlung MongoDB-Einfügung MongoDB-Suche MongoDB-Abfrage MongoDB-Sortierung MongoDB löschen MongoDB-Drop-Sammlung MongoDB-Update MongoDB-Limit

Python-Referenz

Python-Übersicht Eingebaute Python-Funktionen Python-String-Methoden Python-Listenmethoden Methoden des Python-Wörterbuchs Python-Tupelmethoden Python-Set-Methoden Python-Dateimethoden Python-Schlüsselwörter Python-Ausnahmen Python-Glossar

Modulreferenz

Zufallsmodul Anforderungsmodul Statistikmodul Mathe-Modul cMath-Modul

Python-Anleitung

Listenduplikate entfernen Einen String umkehren Fügen Sie zwei Zahlen hinzu

Python-Beispiele

Python-Beispiele Python-Compiler Python-Übungen Python-Quiz Python-Zertifikat

Python-MongoDB- Limit


Begrenzen Sie das Ergebnis

Um das Ergebnis in MongoDB einzuschränken, verwenden wir die limit() Methode.

Die limit()Methode nimmt einen Parameter, eine Zahl, die angibt, wie viele Dokumente zurückgegeben werden sollen.

Stellen Sie sich vor, Sie haben eine "Kunden" -Sammlung:

Kunden

{'_id': 1, 'name': 'John', 'address': 'Highway37'}
{'_id': 2, 'name': 'Peter', 'address': 'Lowstreet 27'}
{'_id': 3, 'name': 'Amy', 'address': 'Apple st 652'}
{'_id': 4, 'name': 'Hannah', 'address': 'Mountain 21'}
{'_id': 5, 'name': 'Michael', 'address': 'Valley 345'}
{'_id': 6, 'name': 'Sandy', 'address': 'Ocean blvd 2'}
{'_id': 7, 'name': 'Betty', 'address': 'Green Grass 1'}
{'_id': 8, 'name': 'Richard', 'address': 'Sky st 331'}
{'_id': 9, 'name': 'Susan', 'address': 'One way 98'}
{'_id': 10, 'name': 'Vicky', 'address': 'Yellow Garden 2'}
{'_id': 11, 'name': 'Ben', 'address': 'Park Lane 38'}
{'_id': 12, 'name': 'William', 'address': 'Central st 954'}
{'_id': 13, 'name': 'Chuck', 'address': 'Main Road 989'}
{'_id': 14, 'name': 'Viola', 'address': 'Sideway 1633'}

Beispiel

Beschränken Sie das Ergebnis auf die Rückgabe von nur 5 Dokumenten:

import pymongo

myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]

myresult = mycol.find().limit(5)

#print the result:
for x in myresult:
  print(x)