-
Notifications
You must be signed in to change notification settings - Fork 19
[Docs+] Getting Started With MongoDB and FastAPI #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for docs-pymongo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed 2/3 of the PR but there are a lot of formatting and style guide issues that It would be good for you to correct before I take a second pass. Let me know if you have any questions!
uvicorn app:app --reload | ||
|
||
.. image:: /includes/integrations/fastapi-terminal.png | ||
:alt: Screenshot of terminal running FastAPI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This step has a lot of indentation errors
|
||
All the code for the example application is stored in ``app.py``. | ||
|
||
Connect to your MongoDB Atlas cluster using the asynchronous `Pymongo Driver <https://www.mongodb.com/docs/languages/python/pymongo-driver/current>`__, then specify the database named ``college``: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this page is now in the pymongo docs, change this link out for something that makes more sense (and use a ref)
FastAPI encodes and decodes data as JSON strings, which do not support all of the | ||
data types that MongoDB's BSON data type can store. BSON has support for | ||
additional non-JSON-native data types, including ``ObjectId`` which is used for | ||
the default UUID attribute, ``_id``. Because of this, you must convert | ||
``ObjectId`` objects to strings before storing them in the ``_id`` field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: fix indentation
# Represents an ObjectId field in the database. | ||
# It will be represented as a `str` on the model so that it can be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: move code to file where possible
|
||
This is the primary model we use as the `response model <https://fastapi.tiangolo.com/tutorial/response-model/>`__ for the majority of our endpoints. | ||
|
||
I want to draw attention to the ``id`` field on this model. MongoDB uses ``_id``, but in Python, underscores at the start of attributes have special meaning. If you have an attribute on your model that starts with an underscore, `pydantic <https://pydantic-docs.helpmanual.io/>`__—the data validation framework used by FastAPI—will assume that it is a private variable, meaning you will not be able to assign it a value! To get around this, we name the field ``id`` but give it an alias of ``_id``. You also need to set ``populate_by_name`` to ``True`` in the model's ``model_config`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: fix for lots of style guide errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still a lot of issues to resolve, I am going OOO so perhaps another team member can pick this up!
- It does not have an ``id`` attribute, as this cannot be modified | ||
- - All fields are optional, so you can supply only the fields you want to update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: list issues
Create Your Application Routes | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Our application has five routes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our application has five routes: | |
The following table describes the application routes you must create to interact with data: |
The application has two read routes: one for viewing all students, and one | ||
for viewing an individual student specified by their ``id``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: convert into a list
recommend using the `skip and limit parameters | ||
<https://pymongo.readthedocs.io/en/stable/api/pymongo/asynchronous/collection.html#pymongo.asynchronous.collection.AsyncCollection.find>`__ | ||
in ``find`` to paginate your results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: not sure why formatting is off here - also use __ at the end of urls (2 underscores)
<https://pymongo.readthedocs.io/en/stable/api/pymongo/asynchronous/collection.html#pymongo.asynchronous.collection.AsyncCollection.find_one_and_update>`__ | ||
to `$set <https://docs.mongodb.com/manual/reference/operator/update/set/>`__ | ||
the new values, and then return the updated document. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use native links such as source constants for API links and :manual:
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-48895
Staging Links
Self-Review Checklist