You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MongoDB collections do not enforce document structure by default, so you have the flexibility to make whatever data-modelling choices best match your application and its performance requirements. So, it's not unusual to create models when working with a MongoDB database.
46
-
47
30
Tutorial
48
31
--------
49
32
33
+
This tutorial walks through the `MongoDB with FastAPI sample project <https://github.com/mongodb-developer/mongodb-with-fastapi>`__.
34
+
50
35
Prerequisites
51
36
~~~~~~~~~~~~~
52
37
@@ -122,6 +107,17 @@ Connect to your MongoDB Atlas cluster using the asynchronous `Pymongo Driver <ht
122
107
123
108
Define Your Database Models
124
109
~~~~~~~~~~~~~~~~~~~~~~~~~~~
110
+
111
+
.. note:: BSON to JSON Mapping
112
+
113
+
FastAPI encodes and decodes data as JSON strings, which do not support all of the
114
+
data types that MongoDB's BSON data type can store. BSON has support for
115
+
additional non-JSON-native data types, including ``ObjectId`` which is used for
116
+
the default UUID attribute, ``_id``. Because of this, you must convert
117
+
``ObjectId`` objects to strings before storing them in the ``_id`` field.
118
+
119
+
For more information about how BSON compares to JSON, see this `JSON and BSON
Our application has three models, the ``StudentModel``, the ``UpdateStudentModel``, and the ``StudentCollection``.
127
123
@@ -380,10 +376,11 @@ More Resources
380
376
381
377
For more information, see the following resources:
382
378
383
-
- Full Stack FastAPI App Generator:
379
+
- MongoDB's Full Stack FastAPI App Generator:
384
380
- `Blog post: Introducing the Full Stack FastAPI App Generator for Python Developers <https://www.mongodb.com/blog/post/introducing-full-stack-fast-api-app-generator-for-python-developers>`__
0 commit comments