|
| 1 | +.. _django-get-started-create-app: |
| 2 | + |
| 3 | +================== |
| 4 | +Query MongoDB Data |
| 5 | +================== |
| 6 | + |
| 7 | +.. facet:: |
| 8 | + :name: genre |
| 9 | + :values: tutorial |
| 10 | + |
| 11 | +.. meta:: |
| 12 | + :keywords: app, odm, code example |
| 13 | + |
| 14 | +.. step:: Query the users collection for a specified email |
| 15 | + |
| 16 | + From the same Python shell as the :ref:`django-get-started-create-app` |
| 17 | + step of this tutorial, run the following code to query the |
| 18 | + ``sample_mflix.users`` collection for a user whose email is |
| 19 | + |
| 20 | + |
| 21 | + .. code-block:: bash |
| 22 | + |
| 23 | + Users.objects.filter(email=" [email protected]").first() |
| 24 | + |
| 25 | + This code returns the name of the matching user: |
| 26 | + |
| 27 | + .. code-block:: bash |
| 28 | + |
| 29 | + <QuerySet [<Users: Khal Drogo>]> |
| 30 | + |
| 31 | +.. step:: Query the movies collection for runtime values |
| 32 | + |
| 33 | + Run the following code to query the ``sample_mflix.movies`` |
| 34 | + collection for movies that have a runtime value less than |
| 35 | + 10: |
| 36 | + |
| 37 | + .. code-block:: bash |
| 38 | + |
| 39 | + Movies.objects.filter(runtime__lt=10) |
| 40 | + |
| 41 | + This code returns a truncated list of the matching movies: |
| 42 | + |
| 43 | + .. code-block:: bash |
| 44 | + |
| 45 | + <QuerySet [<Movies: Winsor McCay, the Famous Cartoonist of the N.Y. |
| 46 | + Herald and His Moving Comics>, <Movies: Steamboat Willie>, <Movies: |
| 47 | + Three Little Pigs>, <Movies: The Band Concert>, <Movies: Who Killed Cock Robin?>, |
| 48 | + <Movies: Dots>, <Movies: The Cat Concerto>, <Movies: Begone Dull Care>, |
| 49 | + <Movies: Mi adorado Juan>, <Movies: Neighbours>, <Movies: A Phantasy>, |
| 50 | + <Movies: Duck Amuck>, <Movies: Duck Dodgers in the 24èth Century>, |
| 51 | + <Movies: Blinkity Blank>, <Movies: One Froggy Evening>, |
| 52 | + <Movies: What's Opera, Doc?>, <Movies: Lines: Horizontal>, |
| 53 | + <Movies: Il fornaretto di Venezia>, <Movies: Dog Star Man: Part IV>, |
| 54 | + <Movies: Now>, '...(remaining elements truncated)...']> |
0 commit comments